Skip to content

Instantly share code, notes, and snippets.

@bicccio
Last active April 29, 2017 00:13
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 bicccio/a4a51dd0f929714278829340c0d052a7 to your computer and use it in GitHub Desktop.
Save bicccio/a4a51dd0f929714278829340c0d052a7 to your computer and use it in GitHub Desktop.
investigate javascript inheritance
var Pet = function (n) {
this.name = n;
this.getName = function() {
return this.name;
}
}
Pet.prototype.getName = function() {
return this.name;
}
var pet = new Pet("picious");
/*
console.log(Pet.prototype);
console.log(pet);
console.log(pet.prototype);
console.log(pet.__proto__)
console.log(pet.getName());
*/
var Cat = function(n) {
Pet.call(this, n);
}
//Cat.prototype = new Pet("ciao");
Cat.prototype = Object.create(Pet.prototype);
var cat = new Cat("ciaone");
console.log(Cat.prototype)
//console.log(cat);
//console.log(cat.prototype);
console.log(cat.__proto__)
//console.log(cat.getName());
console.log(cat.__proto__ == Cat.prototype)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment