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

44 lines
1.2 KiB
JavaScript
Raw Normal View History

2010-07-29 00:51:35 -04:00
var Animal, Horse, Snake, sam, tom;
2010-11-21 12:38:27 -05:00
var __hasProp = Object.prototype.hasOwnProperty, __extends = function(child, parent) {
for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; }
2010-10-19 21:59:13 -04:00
function ctor() { this.constructor = child; }
ctor.prototype = parent.prototype;
2010-10-19 21:59:13 -04:00
child.prototype = new ctor;
child.__super__ = parent.prototype;
2010-11-21 12:38:27 -05:00
return child;
};
2010-11-21 12:38:27 -05:00
Animal = function() {
function Animal(name) {
this.name = name;
}
2010-11-21 12:38:27 -05:00
Animal.prototype.move = function(meters) {
return alert(this.name + " moved " + meters + "m.");
};
2010-10-19 21:59:13 -04:00
return Animal;
2010-11-21 12:38:27 -05:00
}();
Snake = function() {
2010-10-19 21:59:13 -04:00
function Snake() {
2010-11-21 12:38:27 -05:00
Snake.__super__.constructor.apply(this, arguments);
}
2010-11-21 12:38:27 -05:00
__extends(Snake, Animal);
Snake.prototype.move = function() {
alert("Slithering...");
return Snake.__super__.move.call(this, 5);
};
2010-10-19 21:59:13 -04:00
return Snake;
2010-11-21 12:38:27 -05:00
}();
Horse = function() {
2010-10-19 21:59:13 -04:00
function Horse() {
2010-11-21 12:38:27 -05:00
Horse.__super__.constructor.apply(this, arguments);
}
2010-11-21 12:38:27 -05:00
__extends(Horse, Animal);
Horse.prototype.move = function() {
alert("Galloping...");
return Horse.__super__.move.call(this, 45);
};
2010-10-19 21:59:13 -04:00
return Horse;
2010-11-21 12:38:27 -05:00
}();
2010-07-29 00:51:35 -04:00
sam = new Snake("Sammy the Python");
tom = new Horse("Tommy the Palomino");
sam.move();
tom.move();