Last active
August 29, 2015 13:57
-
-
Save lovasoa/9726427 to your computer and use it in GitHub Desktop.
Small coffeescript mixin function. Allows multiple inheritance.
This file contains hidden or 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
mixIn = (classes...) -> | |
classes.reduce ((o,n) -> o::[key]=method for key,method of n::;o), (class) |
This file contains hidden or 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
#How to use: | |
mixIn = (classes...) -> | |
classes.reduce ((o,n) -> o::[key]=method for key,method of n::; o), (class) | |
class A | |
a: -> "I'm class A" | |
class B | |
b: -> "I'm class B" | |
# Here is the magic: C inherits of A and B | |
class C extends mixIn A,B | |
c: -> "I'm class C" | |
c = new C | |
console.log c.a(), c.b(), c.c() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment