Created
January 21, 2019 05:39
-
-
Save AdarshKonchady/98e6e5d78cd38d09395c2fc02aaab9d1 to your computer and use it in GitHub Desktop.
inheritance2.js
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
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