Created
October 25, 2015 10:26
-
-
Save GuyMograbi/f08df757b2ffd283b339 to your computer and use it in GitHub Desktop.
my prefered prototype inheritance pattern
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
// Code goes here | |
function Animal(){ | |
this.type = 'abstract'; | |
this.sayGoodbye = function(){ | |
return 'goodbye'; | |
} | |
} | |
Animal.hasFur = false; | |
function Dog(){ | |
} | |
// Dog.prototype = new Animal(); | |
_.extend(Dog, Animal); | |
Dog.prototype = new Animal(); | |
Dog.prototype.sayHi = function(){ return 'woof' } | |
var dog = new Dog(); | |
console.log('this is type',dog.type); | |
console.log('goodbye', dog.sayGoodbye()); | |
console.log('hi', dog.sayHi()); | |
console.log(Dog.hasFur); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment