Powerful mixins and monkeypatches for coffeescript.
mix = require("coffee-mixin")
class A
constructor: -> console.log "hello"
world: -> console.log "world"
class B
constructor: -> super()
world: -> super()
C = mix A, B
new C().world()
#
# hello
# world
The mix
function takes any number of classes as parameters.
Automatically call super before or after each function is executed.
Transparently monkeypatch, even on constructors!
mix = require("coffee-mixin")
class A
# CoffeeScript does not `return` by default in constructors.
#
constructor: -> return "hel"
world: -> "wor"
class B
constructor: (str) -> console.log "#{str}lo"
world: (str) -> console.log "#{str}ld"
C = mix A, B, prepend: true
new C().world()
#
# hello
# world
mix = require("coffee-mixin")
class A
constructor: (str) -> console.log "#{str}lo"
world: (str) -> console.log "#{str}ld"
class B
# CoffeeScript does not `return` by default in constructors.
#
constructor: -> return "hel"
world: -> "wor"
C = mix A, B, append: true
new C().world()
#
# hello
# world