terratunaz
terratunaz

Reputation: 664

Passing Method into SetTimeOut using CoffeeScript

This is my CoffeeScript code.

setTimeout (-> @checkProgress()), 5000   

When I run this in the browser I get the following error:

TypeError: this.checkProgress is not a function

The method looks like:

checkProgress: ->
    ~ code
    ~ code
    ~ code
    setTimeout (-> @checkProgress()), 5000   

So at some point I want to call the method again. How can I do this? Thanks.

Upvotes: 0

Views: 75

Answers (2)

terratunaz
terratunaz

Reputation: 664

This personally worked perfectly for me as well.

recall = =>
          @checkProgress()
        setTimeout recall, 5000

Upvotes: 0

Tomasz Jakub Rup
Tomasz Jakub Rup

Reputation: 10680

setTimeout run @checkProgress in window context. Use fat arrow:

setTimeout (() => @checkProgress), 5000

Upvotes: 2

Related Questions