-
-
Save EnoF/db78468d6d52f5580ca2 to your computer and use it in GitHub Desktop.
Object or Class creation
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(){} | |
Animal.prototype = { | |
name: 'animal', | |
sayHello: function sayHello(){ | |
return 'Hi, my name is ' + this.name + '!'; | |
} | |
}; | |
function Dog(){} | |
Dog.prototype = new Animal(); | |
var dog = new Dog(); | |
dog instanceof Animal; //True | |
dog.sayHello(); //Hi, my name is animal! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment