I just started to learn that js, saw the section of parasitic combinatorial inheritance on "js elevation", but I don"t quite understand the code given in the book.
what I understand is that parasitic combinatorial inheritance is to avoid the problem of duplicating instance properties and prototype objects in combinatorial inheritance. It inherits the properties in the parent constructor by borrowing the constructor and inherits the prototype object in the parent class using the prototype inheritance method.
this is the code from the book:
function inheritPrototype(SubType,SuperType){
var pro = Object.create(SuperType.prototype);
pro .constructor = SubType;
SubType.prototype = pro ;
}
but how is it different from the following function?
function inheritPrototype(SubType,SuperType){
SubType.prototype = SuperType.prototype;
SubType.prototype.constructor = SubType;
}
I don"t quite understand why we use the method of prototype inheritance to inherit the prototype of the parent class. Isn"t prototype inheritance a shallow copy? What"s the difference between this and direct assignment?