-
-
Save jnicklas/268063 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- COFFEE ------ | |
constructor Animal: name => | |
@name = name | |
Animal.count++ | |
Animal.count: 0 | |
Animal@move: meters => | |
alert(@name + " moved " + meters + "m.") | |
constructor Snake extends Animal | |
Snake@move: => | |
alert("Slithering...") | |
super(5) | |
constructor Horse extends Animal: name => | |
super("horse with a name" + name) | |
Horse@move: => | |
alert("Galloping...") | |
super(45) | |
----- JS ------- | |
var Animal, Snake, Horse; | |
Animal = function Animal(name) { | |
this.name = name; | |
Animal.count ++; | |
// note no return value | |
} | |
Animal.count += 1; | |
Animal.prototype.move = function move(meters) { | |
return alert(this.name + " moved " + meters + "m."); | |
} | |
Snake = function() { | |
var args = Array.prototype.slice.call(arguments, 0, arguments.length); | |
Animal.apply(this, args); | |
// note no return value | |
}; | |
Snake.__superClass__ = Animal.prototype; | |
Snake.prototype = new Animal(); | |
Snake.prototype.constructor = Snake; | |
Snake.prototype.move = function() { | |
alert("Slithering..."); | |
return Snake.__superClass__.move.call(this, 5); | |
}; | |
Horse = function(name) { | |
Animal.call(this, "horse with a name " + name) | |
// note no return value | |
}; | |
Horse.__superClass__ = Animal.prototype; | |
Horse.prototype = new Animal(); | |
Horse.prototype.constructor = Horse; | |
Horse.prototype.move = function() { | |
alert("Galloping..."); | |
return Horse.__superClass__.move.call(this, 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