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'  

fiddle

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() 

see "fiddle"

so mixin snippet works pretty well.


Comments

Popular posts from this blog

php - Why I am getting the Error "Commands out of sync; you can't run this command now" -

linux - Does gcc have any options to add version info in ELF binary file? -

java - Are there any classes that implement javax.persistence.Parameter<T>? -