Skip to content

Instantly share code, notes, and snippets.

@tobyhede
Created July 3, 2013 02:14
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 tobyhede/5914924 to your computer and use it in GitHub Desktop.
Save tobyhede/5914924 to your computer and use it in GitHub Desktop.
Coffeescript super argument ordering. See the snake.
class Animal
constructor: (@name) ->
move: (meters, direction = "north") ->
console.log @name + " moved #{direction} #{meters}m."
class Snake extends Animal
move: (direction = "south", meters = 5) ->
console.log "Slithering..."
super meters, direction
class Horse extends Animal
move: ->
console.log "Galloping..."
super 45
sam = new Snake "Sammy the Python"
tom = new Horse "Tommy the Palomino"
sam.move()
tom.move()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment