Skip to content

Instantly share code, notes, and snippets.

@snorremd
Last active December 26, 2015 17:39
Show Gist options
  • Save snorremd/7188505 to your computer and use it in GitHub Desktop.
Save snorremd/7188505 to your computer and use it in GitHub Desktop.
class Animal
constructor: (@name) ->
@mouth = new Mouth()
@mouth.on("woof", @woof)
this
woof: () ->
@mouth.woof()
class Mouth
constructor: () ->
@dispatchtable = {}
@randomValue = 121241525
this
on: (signal, handler) ->
console.log "Add signal #{signal}"
@dispatchtable[signal] = handler
signal: () ->
@dispatchtable["woof"]
woof: () ->
console.log "Woof"
dog = new Animal "Ikabofs"
console.log JSON.stringify dog
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment