Note: I believe that this reset is no longer needed if using # 2 of the following parameters:
I believe that you can use these options for inheritance:
* 1. done via Object.create (currently I see this syntax more often):
Cat.prototype = Object.create(Mammal.prototype); Cat.prototype.constructor = Cat; //needed anymore?, maybe since when prototype copied its constructor needs to get re-set/changed to the child constructor
* 2. through setPrototypeOf
Object.setPrototypeOf(Cat.prototype, Mammal.prototype); //don't need to reset Cat.prototype.constructor in this case; 'seems smarter'
* 3. through a new one; I do not think that this method is recommended anymore (although this is exactly how I learned to establish inheritance many years ago). I believe that reading prototype settings this way using 'new ParentClass ()' is no longer recommended, as it will copy properties that are not needed in the prototype, I believe (the properties that you usually set in an instance with super (constructorParams) or ParentClass.call (this, constructorParams) in the Cat constructor / function, so they should be shared by all instances through the prototype).
Cat.prototype = new Mammal(); Cat.prototype.constructor=Cat;
armyofda12mnkeys
source share