阮一峰文檔備忘
構(gòu)造函數(shù)的繼承:原文地址
- 對(duì)Cat的prototype對(duì)象重新賦值,相當(dāng)于完全刪除了prototype 對(duì)象原先的值,然后賦予一個(gè)新值
Cat.prototype = new Animal();
- 任何一個(gè)prototype對(duì)象都有一個(gè)constructor屬性,指向它的構(gòu)造函數(shù)。
alert(Cat.prototype.constructor == Animal); //true
- 每一個(gè)實(shí)例也有一個(gè)constructor屬性,默認(rèn)調(diào)用prototype對(duì)象的constructor屬性。
alert(cat1.constructor == Cat.prototype.constructor); // true
- 編程時(shí)務(wù)必要遵守:如果替換了prototype對(duì)象,那么,下一步必然是為新的prototype對(duì)象加上constructor屬性,并將這個(gè)屬性指回原來的構(gòu)造函數(shù)。
o.prototype = {};
o.prototype.constructor = o;
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。