I’d like to changing the binding of the callback function in a child class so that the following code indicates 20, rather than 10:
class A
@in = 10
@b: =>
alert(@in)
class B extends A
@in = 20
@w: ->
window.setTimeout(@b,500)
B.w()
If I ‘thin-arrow’ the definition of A.b, then the binding is to the timeout calling function so @in is undefined. When I fat-arrow it, it binds to the parent class A. I would like it to bind to the child class B, without redefining the method in the child class.
Thanks
I think the best you can do is force the appropriate binding manually when you set up your
setTimeoutcall. Drop the=>when defining@binA:And then set the binding in
Bwhen you callsetTimeout:I think that’s as close as you can get using CoffeeScript’s pseudo-class-methods.
Demo: http://jsfiddle.net/ambiguous/Y6S8D/