CoffeeScript mixin doesn't work -
i found example of mixins in coffeescript faq seems doesn't work.
am missing here?
extend = (obj, mixin) -> name, method of mixin obj[name] = method include = (klass, mixin) -> extend klass.prototype, mixin class button onclick: -> alert "click" class events include button, events (new events).onclick() # => uncaught typeerror: object #<events> has no method 'onclick'
you missing fact onclick defined on prototype of button, , did not set arguments right order in include function
extend = (obj, mixin) -> name, method of mixin obj[name] = method include = (klass, mixin) -> extend klass.prototype, mixin class button onclick: -> alert "click" class events include events,button.prototype (new events).onclick() so mixin snippet works pretty well.
Comments
Post a Comment