Skip to content

Instantly share code, notes, and snippets.

@GuyMograbi
Created October 25, 2015 10:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GuyMograbi/f08df757b2ffd283b339 to your computer and use it in GitHub Desktop.
Save GuyMograbi/f08df757b2ffd283b339 to your computer and use it in GitHub Desktop.
my prefered prototype inheritance pattern
// 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