Last active
December 26, 2015 17:39
-
-
Save snorremd/7188505 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
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