Skip to content

Instantly share code, notes, and snippets.

@tamanyan
Created September 30, 2013 01:31
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 tamanyan/6758302 to your computer and use it in GitHub Desktop.
Save tamanyan/6758302 to your computer and use it in GitHub Desktop.
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