Created
August 27, 2014 20:54
-
-
Save donut/00e407abb7cece0bcdfa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
###* | |
* @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