forked from jashkenas/coffeescript
-
Notifications
You must be signed in to change notification settings - Fork 1
Home
StanAngeloff edited this page Aug 27, 2010
·
27 revisions
Welcome to the CoffeeScript Wiki!
Want to help CoffeeScript? Read about contributing!
(these will be separated in a new page as content gets added)
-
Q: Will you support multiple inheritance/mixins/imports/interfaces/traits or any other fancy class extensions?
A: The short answer is no. You can do any of the above using helpers.
Solution (1) courtesy of jashkenas:
extend = (obj, mixin) ->
for name, method of mixin
obj[name] = method
include = (klass, mixin) ->
extend klass.prototype, mixin
class Button
onClick: -> # do stuff
include Button, Options
include Button, Events
Solution (2) courtesy of sethaurus:
implementing = (mixins..., classReference) ->
for mixin in mixins
for key, value of mixin::
(classReference::)[key] = value
classReference
Button = implementing Options, Events, class _Button
onClick: -> # do stuff
If you want to learn more, please read these issues on the tracker: #218, #327, #344, #452 and #636. They should have all the pros and cons and why mixins are not part of the core language.