You request the setTimeout function to evaluate "this.runShow()" , and setTimeout will do this in the window context. This means that this is a window object when this code is evaluated.
To avoid this, you can create a function and bind it to the current context, so that every time the function is called, this is the same as the function was created.
In a coffee script, you can do this with => :
func = => this.runShow() setTimeout(func, 2000)
Or in one line:
setTimeout((=> this.runShow()), 2000)
how can i reference t to another function?
Make the t property of your object:
class Something t: null runShow: -> ... this.t = ... otherFunction: -> t = this.t
source share