jashkenas--coffeescript/documentation/coffee/classes.coffee

26 lines
358 B
CoffeeScript
Raw Normal View History

class Animal
2010-11-21 17:38:27 +00:00
constructor: (@name) ->
2010-07-29 04:51:35 +00:00
move: (meters) ->
alert @name + " moved " + meters + "m."
class Snake extends Animal
move: ->
alert "Slithering..."
super 5
class Horse extends Animal
move: ->
alert "Galloping..."
super 45
2009-12-21 16:41:45 +00:00
2010-07-29 04:51:35 +00:00
sam = new Snake "Sammy the Python"
tom = new Horse "Tommy the Palomino"
2009-12-21 16:41:45 +00:00
sam.move()
tom.move()
2009-12-24 06:22:41 +00:00