一步步揭开 原型链的面纱 面试再也不慌 原型链

一步步 深入解析 原型链的奥秘

一切的开始从人类开始说起

function person(){};

const Adam = new person();

// 函数实例化 出 Adam(亚当)这个对象  利用关键字new

复制代码

console.log(Adam.__proto__);
console.log(Adam.__proto__.constructor)  // function person(){}
console.log(person.prototype) //Adam原型对象
console.log(person.prototype === Adam.__proto__) //true

// 实例的__proto__指的是 创造该实例的原型对象
复制代码

万物皆对象

console.log(Adam.__proto__.__proto__) // Object 原型对象
console.log(Adam.__proto__.__proto__.__proto__)//null
console.log(Adam.__proto__.__proto__.constructor)//function Object(){ [native code] }
console.log(Adam.__proto__.__proto__.constructor.prototype)//Object原型对象

复制代码
  • 只有函数才有 prototype 指向原型对象
  • 万物都是对象
  • 原型对象利用 constructor 构造函数 创建实例
  • [native code] 这里是底层 C 并不对外开放

一切普通的函数都是由大 Function 来制造来的

console.log(person.__proto__)//Function 原型对象
console.log(Adam.__proto__.__proto__.constructor.__proto__ === person.__proto__)
//true  这两个都是函数 
// 所以 __proto__皆指向 大Function的原型对象
console.log(person.__proto__.__proto__)
//万般皆是命 ,全都是对象
复制代码

特殊的大 Function

console.log(person.__proto__.constructor) //function Function(){ [native code] }
console.log(person.__proto__.constructor.prototype)
// 大Function 的原型对象
复制代码

注意这里

  • console.log(person.__proto__.constructor.__proto__ === person.__proto__) // true
  • 大Function的 __proto__又指☞回了 大Function的原型对象

##总结:

  • 只有function 才存在 prototype
  • 原型对象 存在着 constructor
  • 实例的 __proto__指向 原型对象
  • 大Function的 proto 指回了 Function原型对象
  • 普通函数的 proto 指向 Function原型对象
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值