Skip to content

Instantly share code, notes, and snippets.

@flyingzl
Created January 23, 2013 13:13
Show Gist options
  • Save flyingzl/4605421 to your computer and use it in GitHub Desktop.
Save flyingzl/4605421 to your computer and use it in GitHub Desktop.
var __hasProp = {}.hasOwnProperty,
__extends = function(child, parent) {
for (var key in parent) {
if (__hasProp.call(parent, key))
child[key] = parent[key];
}
function ctor() {
this.constructor = child;
}
ctor.prototype = parent.prototype;
child.prototype = new ctor();
child.__super__ = parent.prototype;
return child;
};
Animal = (function() {
function Animal(name) {
this.name = name;
}
Animal.prototype.move = function(meters) {
console.log(this.name + (" moved " + meters + "m."));
};
return Animal;
})();
Snake = (function(_super) {
__extends(Snake, _super);
function Snake() {
return Snake.__super__.constructor.apply(this, arguments);
}
Snake.prototype.move = function() {
console.log("Slithering...");
return Snake.__super__.move.call(this, 5);
};
return Snake;
})(Animal);
Horse = (function(_super) {
__extends(Horse, _super);
function Horse() {
return Horse.__super__.constructor.apply(this, arguments);
}
Horse.prototype.move = function() {
console.log("Galloping...");
return Horse.__super__.move.call(this, 45);
};
return Horse;
})(Animal);
new Snake("snake").move();
new Horse("horse").move()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment