Skip to content

Instantly share code, notes, and snippets.

@thelinuxlich
Created November 11, 2013 19:17
Show Gist options
  • Save thelinuxlich/7418706 to your computer and use it in GitHub Desktop.
Save thelinuxlich/7418706 to your computer and use it in GitHub Desktop.
Herança em JS do jeito certo
function Animal(name) {
this.name = name;
};
Animal.prototype.move = function(meters) {
console.log(this.name+" moved "+meters+"m.");
};
function Snake() {
Animal.apply(this, Array.prototype.slice.call(arguments));
};
Snake.prototype = new Animal();
Snake.prototype.move = function() {
console.log("Slithering...");
Animal.prototype.move.call(this, 5);
};
var sam = new Snake("Sammy the Python");
sam.move();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment