Skip to content

Instantly share code, notes, and snippets.

@donut
Created August 27, 2014 20:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save donut/00e407abb7cece0bcdfa to your computer and use it in GitHub Desktop.
Save donut/00e407abb7cece0bcdfa to your computer and use it in GitHub Desktop.
###*
* @file
* Provides mixin support for classes.
* @url https://gist.github.com/donut/00e407abb7cece0bcdfa
* @see http://coffeescriptcookbook.com/chapters/classes_and_objects/mixins
###
module.exports = (base, mixins...) ->
constructors = []
class Mixed extends base
_construct_mixins: (args...) ->
constructor.apply(@, args) for constructor in constructors
for mixin in mixins by -1 # Earlier mixins override later ones.
constructors.push mixin
for name, method of mixin::
Mixed::[name] = method
Mixed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment