Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Animal
- constructor: (@name) ->
- move: (meters) ->
- @position += meters
- console.log @name + " moved #{meters}m."
- position: 0
- class Snake extends Animal
- slither: ->
- @move(3)
- class Horse extends Animal
- gallop: ->
- @move(10)
- sam = new Snake "Sammy the Python"
- tom = new Horse "Tommy the Palomino"
- sam.move(1)
- sam.slither()
- tom.gallop()
- console.log("#{sam.name} moved #{sam.position}m total");
- console.log("#{tom.name} moved #{tom.position}m total");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement