关于原型链

笔记重点:

根部的 Object.prototype == null;
空函数._proto_ == Object.prototype

原型链绘图

注解:
Person为父构造函数,Girl为子构造函数。原型链继承原理:子构造函数.prototype = new 父构造函数()。

《关于原型链》 原型链绘图.png

console.log(Object instanceof Object);
// 构造函数(Object)的原型对象(Object.prototype)是否在当前对象(Object)的原型链中,true
console.log(Function instanceof Function);
//构造函数(Function)的原型对象(空函数)是否在当前对象(Function)的原型链中 true
console.log(Function instanceof Object);
//构造函数(Object)的原型对象(Object.prototype)是否在当前对象(Function)的原型链中,true
console.log(Object instanceof Function);
//Function的原型对象(空函数)是否在Object的原型链中,true

详细推论

  1. 构造函数本身是函数,函数本质是对象,每一个对象都有构造函数,因此构造函数也有他自己的构造函数。故:
Girl.constructor == Function;
  1. Function的原型对象是一个空函数
Function.prototype == function(){};//空函数
  1. Function是一个构造函数,同1中推理,因此Function有自己的构造函数。
Function.constructor == Function;
  1. Function对象的原型对象应该等于它的构造函数的原型对象。
Function.__proto__  == Function.constructor.prototype == Function.prototype == function(){}//空函数
  1. Object本身是一个构造函数,再同1中推理,因此有自己的构造函数。
Object.constructor == Function
  1. Object对象的原型对象应该等于它构造函数的原型对象
Object.__proto__ == Object.constructor.prototype == Function.prototype == function(){}//空函数

综上推论:
空函数的原型对象应该等于它构造函数的原型对象,即:

空函数.__proto__ == 空函数.constructor.prototype == Function.prototype == 空函数 ?????

!!!!!!重点:!!!!!!!
上述推论时错误的!
正确如下:

空函数.__proto__ == Object.prototype

笔记重点:(首尾呼应,加深印象!!!)
根部的 Object.prototype == null;
空函数._proto_ == Object.prototype

    原文作者:ForeverYoung20
    原文地址: https://www.jianshu.com/p/a62ec87dc8d6
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞