Last active
August 29, 2015 13:56
-
-
Save EnoF/8930612 to your computer and use it in GitHub Desktop.
Overriding the Bad way
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(); | |
Dog.prototype.sayHello = function sayHello(){ | |
return 'Hello, my name is ' + this.name + '!'; | |
}; | |
var dog = new Dog(); | |
dog instanceof Animal; //True | |
dog.sayHello(); //Hello, my name is animal! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment