An alternative solution that is closer to what you are doing in ES5 is this:
pingMe: -> setTimeout(@doPing.bind(@), 1000)
or if you want to keep in parentheses:
pingMe: -> setTimeout (@doPing.bind @), 1000
Please note that bind is ES5, therefore it is only available in IE from version 9.
Also note: you should avoid the temptation to try:
setTimeout(@doPing.bind @, 1000)
because both of them pass the number as the second argument to bind , not setTimeout !
joeytwiddle
source share