You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Yay classes! Maybe we could have Ruby's extend/include to mix in stuff in our classes? We can make it way cooler than Ruby by allowing any Object to be mixed in!
nameMixin: { name: 'Steve' }
makeSteveMixin: { steve: -> new this() }
class Person
include nameMixin
extend makeSteveMixin
steve: new Person
steve.name() #=> 'Steve'
steve2: Person.steve
The text was updated successfully, but these errors were encountered:
It's all just attaching functions to the proper location. I don't think that we need to formalize this pattern in CoffeeScript, as many core libraries (jQuery, Prototype, Underscore) already have this extend function, and many objects that are intended for use as mixins already have it built-in. Any many people prefer helper objects and composition over mixing methods right in to the prototype.
So, closing as a 'wontfix'.
But if you use the methods above, your example could be written like so:
nameMixin: { name: 'Steve' }
makeSteveMixin: { steve: -> new this() }
class Person
include Person, nameMixin
extend Person, makeSteveMixin
steve: new Person()
puts steve.name
steve2: Person.steve
Yay classes! Maybe we could have Ruby's extend/include to mix in stuff in our classes? We can make it way cooler than Ruby by allowing any Object to be mixed in!
The text was updated successfully, but these errors were encountered: