1
0
Fork 0
mirror of https://github.com/jashkenas/coffeescript.git synced 2022-11-09 12:23:24 -05:00
jashkenas--coffeescript/documentation/js/classes.js

38 lines
1 KiB
JavaScript
Raw Normal View History

2009-12-21 11:41:45 -05:00
(function(){
2010-02-27 20:12:47 -05:00
var Animal, Horse, Snake, sam, tom;
var __extends = function(child, parent) {
var ctor = function(){ };
ctor.prototype = parent.prototype;
child.prototype = new ctor();
child.prototype.constructor = child;
if (typeof parent.extended === "function") parent.extended(child);
child.__superClass__ = parent.prototype;
2010-02-27 20:12:47 -05:00
};
Animal = function() {};
2010-05-15 01:18:05 -04:00
Animal.prototype.move = function(meters) {
2009-12-21 11:41:45 -05:00
return alert(this.name + " moved " + meters + "m.");
};
2010-05-15 01:18:05 -04:00
Snake = function(name) {
this.name = name;
return this;
};
2010-02-27 20:12:47 -05:00
__extends(Snake, Animal);
2010-05-15 01:18:05 -04:00
Snake.prototype.move = function() {
alert("Slithering...");
return Snake.__superClass__.move.call(this, 5);
};
2010-05-15 01:18:05 -04:00
Horse = function(name) {
this.name = name;
return this;
};
2010-02-27 20:12:47 -05:00
__extends(Horse, Animal);
2010-05-15 01:18:05 -04:00
Horse.prototype.move = function() {
alert("Galloping...");
return Horse.__superClass__.move.call(this, 45);
};
2009-12-26 02:17:34 -05:00
sam = new Snake("Sammy the Python");
tom = new Horse("Tommy the Palomino");
2009-12-21 11:41:45 -05:00
sam.move();
tom.move();
2010-02-24 18:27:10 -05:00
})();