Skip to content

Instantly share code, notes, and snippets.

@danshearmur
Created April 4, 2013 14:13
Show Gist options
  • Save danshearmur/5310686 to your computer and use it in GitHub Desktop.
Save danshearmur/5310686 to your computer and use it in GitHub Desktop.
function Animal (name, numLegs) {
this.name = name;
this.numLegs = numLegs;
}
Animal.prototype.greet = function () {
console.log("Hi! My name is " + this.name);
}
function Horse (name) {
this.name = name;
this.numLegs = 4;
}
Horse.prototype = Animal.prototype;
var tom = new Animal('tom', 8);
tom.greet(); // Hi! My name is tom
var nelly = new Horse('nelly');
nelly.greet(); // Hi! My name is nelly
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment