Created
September 30, 2013 01:31
-
-
Save tamanyan/6758302 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
mixOf = (base, mixins...) -> | |
class Mixed extends base | |
for mixin in mixins by -1 #earlier mixins override later ones | |
for name, method of mixin:: | |
Mixed::[name] = method | |
Mixed | |
class DeepThought | |
answer: -> | |
42 | |
class PhilosopherMixin | |
pontificate: -> | |
console.log "hmm..." | |
@wise = yes | |
class DeeperThought extends mixOf DeepThought, PhilosopherMixin | |
answer: -> | |
@pontificate() | |
super() | |
earth = new DeeperThought | |
earth.answer() | |
# hmm... | |
# => 42 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment