Skip to content

Instantly share code, notes, and snippets.

@EnoF
Last active August 29, 2015 13:56
Show Gist options
  • Save EnoF/8930612 to your computer and use it in GitHub Desktop.
Save EnoF/8930612 to your computer and use it in GitHub Desktop.
Overriding the Bad way
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