Skip to content

Instantly share code, notes, and snippets.

@madis
Created March 11, 2013 21:45
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 madis/5138069 to your computer and use it in GitHub Desktop.
Save madis/5138069 to your computer and use it in GitHub Desktop.
Playing with coffeescript inheritance
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