Skip to content

Instantly share code, notes, and snippets.

@AdarshKonchady
Created January 21, 2019 05:39
Show Gist options
  • Save AdarshKonchady/98e6e5d78cd38d09395c2fc02aaab9d1 to your computer and use it in GitHub Desktop.
Save AdarshKonchady/98e6e5d78cd38d09395c2fc02aaab9d1 to your computer and use it in GitHub Desktop.
inheritance2.js
function Animal() {
this.offspring = [];
}
function Dog() {
Animal.call(this); // Use Animal.call(this, args) if any arguments
// exist. Else, use 'apply'
}
Dog.prototype = Object.create(Animal.prototype);
Dog.prototype.constructor = Dog;
var d1 = new Dog();
var d2 = new Dog();
var pup = new Dog();
d1.offspring.push(pup); // Dog {offspring: Array[1]}
d2.offspring; // Dog {offspring: Array[0]}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment