0
爲什麼我們需要在繼承之後將Child.prototype.constructor
屬性設置爲Child
。例如爲什麼重寫繼承的構造函數字段
function Parent(a){
this.a = a;
}
function Child(a, b){
Parent.call(this. a);
this.b = b;
}
Child.prototype = Object.create(Parent.prototype);
Child.prototype.constructor = Child // 1)**
當我看到構造函數的實例將是相同的,而不// 1) **
線
爲什麼我們需要這個// 1) **
行?
可能重複[爲什麼需要設置原型構造?](https://stackoverflow.com/questions/8453887/why-is-it-necessary -to-設置的原型構造函數) –