Skip to content

Instantly share code, notes, and snippets.

@danilodeveloper
Created May 21, 2015 18:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danilodeveloper/62422ff29d590f2a3d27 to your computer and use it in GitHub Desktop.
Save danilodeveloper/62422ff29d590f2a3d27 to your computer and use it in GitHub Desktop.
Herança Javascript
// No Node.js é melhor usar o Util.inherits (https://nodejs.org/docs/latest/api/util.html#util_util_inherits_constructor_superconstructor)
var __extends = this.__extends || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
__.prototype = b.prototype;
d.prototype = new __();
};
var Animal = (function () {
function Animal(name) {
this.name = name;
}
Animal.prototype.move = function (meters) {
alert(this.name + " moved " + meters + "m.");
};
return Animal;
})();
var Snake = (function (_super) {
__extends(Snake, _super);
function Snake(name) {
_super.call(this, name);
}
Snake.prototype.move = function () {
alert("Slithering...");
_super.prototype.move.call(this,5);
};
return Snake;
})(Animal);
var Horse = (function (_super) {
__extends(Horse, _super);
function Horse(name) {
_super.call(this, name);
}
Horse.prototype.move = function () {
alert("Galloping...");
_super.prototype.move.call(this, 45);
};
return Horse;
})(Animal);
var sam = new Snake("Sammy the Python");
var tom = new Horse("Tommy the Palomino");
sam.move();
tom.move(34);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment