筆記重點(diǎn):
根部的 Object.prototype == null;
空函數(shù)._proto_ == Object.prototype
原型鏈繪圖
注解:
Person為父構(gòu)造函數(shù)亡电,Girl為子構(gòu)造函數(shù)。原型鏈繼承原理:子構(gòu)造函數(shù).prototype = new 父構(gòu)造函數(shù)()摩骨。
原型鏈繪圖.png
console.log(Object instanceof Object);
// 構(gòu)造函數(shù)(Object)的原型對象(Object.prototype)是否在當(dāng)前對象(Object)的原型鏈中,true
console.log(Function instanceof Function);
//構(gòu)造函數(shù)(Function)的原型對象(空函數(shù))是否在當(dāng)前對象(Function)的原型鏈中 true
console.log(Function instanceof Object);
//構(gòu)造函數(shù)(Object)的原型對象(Object.prototype)是否在當(dāng)前對象(Function)的原型鏈中,true
console.log(Object instanceof Function);
//Function的原型對象(空函數(shù))是否在Object的原型鏈中,true
詳細(xì)推論
- 構(gòu)造函數(shù)本身是函數(shù)竭讳,函數(shù)本質(zhì)是對象州刽,每一個對象都有構(gòu)造函數(shù)辕狰,因此構(gòu)造函數(shù)也有他自己的構(gòu)造函數(shù)。故:
Girl.constructor == Function;
- Function的原型對象是一個空函數(shù)
Function.prototype == function(){};//空函數(shù)
- Function是一個構(gòu)造函數(shù)唬复,同1中推理矗积,因此Function有自己的構(gòu)造函數(shù)。
Function.constructor == Function;
- Function對象的原型對象應(yīng)該等于它的構(gòu)造函數(shù)的原型對象敞咧。
Function.__proto__ == Function.constructor.prototype == Function.prototype == function(){}//空函數(shù)
- Object本身是一個構(gòu)造函數(shù)棘捣,再同1中推理,因此有自己的構(gòu)造函數(shù)休建。
Object.constructor == Function
- Object對象的原型對象應(yīng)該等于它構(gòu)造函數(shù)的原型對象
Object.__proto__ == Object.constructor.prototype == Function.prototype == function(){}//空函數(shù)
綜上推論:
空函數(shù)的原型對象應(yīng)該等于它構(gòu)造函數(shù)的原型對象乍恐,即:
空函數(shù).__proto__ == 空函數(shù).constructor.prototype == Function.prototype == 空函數(shù) ?测砂?茵烈??瞧毙?
<闹ⅰ!J推帷@河L鸪鳌!重點(diǎn):D疡伞!9犹怠V⒙恰5尽!骗污!
上述推論時錯誤的沈条!
正確如下:
空函數(shù).__proto__ == Object.prototype
筆記重點(diǎn):(首尾呼應(yīng),加深印象@酢!:谷鳌)
根部的 Object.prototype == null;
空函數(shù)._proto_ == Object.prototype