/documentation/coffee/classes.coffee

http://github.com/jashkenas/coffee-script · CoffeeScript · 21 lines · 16 code · 5 blank · 0 comment · 0 complexity · f6afff56d42a4296147b583221eabf20 MD5 · raw file

  1. class Animal
  2. constructor: (@name) ->
  3. move: (meters) ->
  4. alert @name + " moved #{meters}m."
  5. class Snake extends Animal
  6. move: ->
  7. alert "Slithering..."
  8. super 5
  9. class Horse extends Animal
  10. move: ->
  11. alert "Galloping..."
  12. super 45
  13. sam = new Snake "Sammy the Python"
  14. tom = new Horse "Tommy the Palomino"
  15. sam.move()
  16. tom.move()