In js classic inheritance, why do you use borrowed constructors instead of directly using constructors?

such as the title, I recently found a puzzling problem when I was flipping through the Red Treasure Book.
mentions combinatorial inheritance in the chapter of 6.3inheritance, which is explained as follows:

clipboard.png

js:

clipboard.png

so here comes the problem. We all know what the prototype chain and constructor are, so what about borrowing the constructor?

then give an example of borrowing a constructor:

function SuperType(){
    this.colors = ["red", "blue", "green"];
} 
 
function SubType(){
    // SuperType 
    SuperType.call(this);
} 
 
var instance1 = new SubType(); instance1.colors.push("black");
alert(instance1.colors);    //"red,blue,green,black" 
 
var instance2 = new SubType();
alert(instance2.colors);    //"red,blue,green"

what puzzles me is why the constructor is borrowed, as in the above code, the superclass is called in the parent class to add subclass private properties to the subclass.
Why can"t this be done using a constructor?
Constructors can be implemented as well, and constructors are simpler than borrowing constructor structures. In the example where
is changed to a constructor, the utility is the same as borrowing the constructor:

function SubType() {
  this.colors = ["red", "blue", "green"];
}

var instance1 = new SubType();
instance1.colors.push("black");
alert(instance1.colors); //"red,blue,green,black" 

var instance2 = new SubType();
alert(instance2.colors); //"red,blue,green"

so let me emphasize my question again: why use borrowing constructors in combinatorial inheritance instead of using constructors directly? In my opinion, constructors are simpler and functionally consistent than borrowing constructors.

Apr.01,2021

what's the name of inheritance when the two are independent?
if you change something in the parent class, such as deleting the red field, there is no relationship between the two subclasses that directly use the constructor.

function SuperType(){
    this.colors = ["red", "blue", "green"];
} 
 
function SubType1(){
    // SuperType 
    SuperType.call(this);
    this.colors.push("black")
}
function SubType2(){
    // SuperType 
    SuperType.call(this);
    this.colors.push("white")
}

if one day modify colors delete red , then just modify the parent class:

function SuperType(){
    this.colors = ["blue", "green"];
}

if they are all independent, then 100 subclasses should be modified 100 times

.

No, combinatorial inheritance and constructor are basically two concepts, one is for inheritance, the other is simply for instantiation, and the concepts are different.
Why should I use borrowing constructors for combinatorial inheritance? Because if I inherit from the prototype chain, when I change the attribute on the subclass that inherits from the parent class, especially the reference attribute , it will also be modified along with that attribute on the parent class, resulting in misoperation.
if you use a borrowed constructor, because the properties inherited by the borrowing constructor are only based on the copy of the properties of the parent class, and have nothing to do with the parent class, so when you need to change a property inherited by the borrowing constructor, you will find that just changing the parent class will not work. To modify all of them, you have to modify as many subclasses as there are. In addition, if all borrowing constructors are used, there will be unnecessary memory overhead when there are many properties of the parent class methods.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1bf450f-31eed.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1bf450f-31eed.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?