Skip to content

Instantly share code, notes, and snippets.

@lovasoa
Last active August 29, 2015 13:57
Show Gist options
  • Save lovasoa/9726427 to your computer and use it in GitHub Desktop.
Save lovasoa/9726427 to your computer and use it in GitHub Desktop.
Small coffeescript mixin function. Allows multiple inheritance.
mixIn = (classes...) ->
classes.reduce ((o,n) -> o::[key]=method for key,method of n::;o), (class)
#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