Created
March 11, 2013 21:45
-
-
Save madis/5138069 to your computer and use it in GitHub Desktop.
Playing with coffeescript inheritance
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 Base | |
@doSomething: (@origin) -> | |
console.log "Base.doSomething called" | |
@showSomething: -> | |
console.log "Showing something", @things | |
@createSomething: (something) -> | |
new @ | |
instanceShow: -> | |
console.log "In instance show" | |
console.log "is operator ? ", @constructor == Operator | |
console.log "is visitor ? ", @constructor == Visitor | |
@constructor.showSomething() | |
# Operator.showSomething() | |
class Operator extends Base | |
@setup: (@things) -> | |
# Operator.things = things | |
Base.doSomething('from visitor') | |
@showSomething() | |
class Visitor extends Base | |
@setup: (@things) -> | |
# Visitor.things = things | |
Base.doSomething('from visitor') | |
@showSomething() | |
Operator.setup('operator things') | |
Visitor.setup('visitor things') | |
console.log 'Back to operator' | |
Operator.showSomething() | |
op = new Operator | |
op.instanceShow() | |
vi = new Visitor | |
vi.instanceShow() | |
console.log "Did we get operator?", Operator.createSomething() instanceof Operator | |
console.log "Did we get visitor?", Visitor.createSomething() instanceof Visitor | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment