coffeescript how to set binding" to a child class in a callback function defined in parent class -
coffeescript how to set binding" to a child class in a callback function defined in parent class -
i'd changing binding of callback function in kid class next code indicates 20, rather 10:
class @in = 10 @b: => alert(@in) class b extends @in = 20 @w: -> window.settimeout(@b,500) b.w() if 'thin-arrow' definition of a.b, binding timeout calling function @in undefined. when fat-arrow it, binds parent class a. bind kid class b, without redefining method in kid class.
thanks
i think best can forcefulness appropriate binding manually when set settimeout call. drop => when defining @b in a:
class #... @b: -> alert(@in) and set binding in b when phone call settimeout:
class b extends #... @w: -> f = => @b() window.settimeout(f, 500) i think that's close can using coffeescript's pseudo-class-methods.
demo: http://jsfiddle.net/ambiguous/y6s8d/
coffeescript
Comments
Post a Comment