Created
April 4, 2013 14:13
-
-
Save danshearmur/5310686 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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