Skip to content

Instantly share code, notes, and snippets.

@bobishh
Last active September 14, 2016 09:26
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 bobishh/1a972f10abf2d39738c078054bd7ed83 to your computer and use it in GitHub Desktop.
Save bobishh/1a972f10abf2d39738c078054bd7ed83 to your computer and use it in GitHub Desktop.
CoffeeScript inheritance model
class Animal
constructor: (@name) ->
@kind = 'animal'
say_hello: ->
alert "Hello human! I'm #{@kind} named #{@name}"
alterVoice: (voice) ->
@voice = voice
class Dog extends Animal
constructor: (@name) ->
@kind = 'dog'
@voice = 'bow-wow!'
bark: ->
alert @voice
dog = new Dog('Louie')
dog.bark()
dog.say_hello()
dog.alterVoice("meow-meow!")
dog.bark()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment