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

42 lines
1.1 KiB
JavaScript
Raw Normal View History

2010-07-29 00:51:35 -04:00
var Animal, Horse, Snake, sam, tom;
var __extends = function(child, parent) {
var ctor = function(){};
2010-02-27 20:12:47 -05:00
ctor.prototype = parent.prototype;
child.prototype = new ctor();
child.prototype.constructor = child;
if (typeof parent.extended === "function") parent.extended(child);
2010-08-23 22:08:33 -04:00
child.__super__ = parent.prototype;
2010-02-27 20:12:47 -05:00
};
2010-10-04 23:21:16 -04:00
Animal = (function() {
return function Animal(_arg) {
this.name = _arg;
return this;
};
})();
2010-07-29 00:51:35 -04:00
Animal.prototype.move = function(meters) {
return alert(this.name + " moved " + meters + "m.");
};
2010-10-04 23:21:16 -04:00
Snake = (function() {
return function Snake() {
return Animal.apply(this, arguments);
};
})();
2010-07-29 00:51:35 -04:00
__extends(Snake, Animal);
Snake.prototype.move = function() {
alert("Slithering...");
2010-08-23 22:08:33 -04:00
return Snake.__super__.move.call(this, 5);
2010-07-29 00:51:35 -04:00
};
2010-10-04 23:21:16 -04:00
Horse = (function() {
return function Horse() {
return Animal.apply(this, arguments);
};
})();
2010-07-29 00:51:35 -04:00
__extends(Horse, Animal);
Horse.prototype.move = function() {
alert("Galloping...");
2010-08-23 22:08:33 -04:00
return Horse.__super__.move.call(this, 45);
2010-07-29 00:51:35 -04:00
};
sam = new Snake("Sammy the Python");
tom = new Horse("Tommy the Palomino");
sam.move();
tom.move();