Skip to content

Instantly share code, notes, and snippets.

@hojberg
Created March 9, 2010 19:28
Show Gist options
  • Save hojberg/326988 to your computer and use it in GitHub Desktop.
Save hojberg/326988 to your computer and use it in GitHub Desktop.
# Classical
class Animal
color: 'brown'
sleep: (minutes) ->
"sleeping for " + minutes + " minutes"
class Horse extends Animal
legs: 4
gallop: ->
"galloping happily"
ed: new Horse
ed.sleep(5) # => sleeping for 5 minutes
ed.gallop() # => galloping happily
# Prototypal
Animal: {
color: brown
sleep: (minutes) ->
"sleeping for " + minutes + " minutes"
}
Horse: clone Animal
legs: 4
gallop: ->
"galloping happily"
ed: clone Horse
ed.sleep(5) # => sleeping for 5 minutes
ed.gallop() # => galloping happily
Horse.gallop: (speed) ->
"galloping happily at the speed of " + speed " mph"
ed.gallop(1) # => galloping happily at the speed of 1 mph
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment