I started writing coffeescript last week since I am programming a new Play20 site where coffeescript is standard. I want to update the getData function in my class every 5 minutes, but the setInterval function does not bind to my class. Only the first time it calls getData, because the 'this' object is still available, since the setUpdateInterval () function is called from the constructor.
But after the first call, setInterval no longer has any connection with the Widget instance and does not know what this.getData () function is (and how to achieve it).
Does anyone know how to do this?
Here is my code:
class Widget
constructor: (@name) ->
this.setUpdateInterval()
getData: ->
console.log "get Data by Ajax"
setUpdateInterval: (widget) ->
setInterval( this.getData(), 3000000 )
Jacob source
share