美文网首页
2020-02-20 Function与Object的关系

2020-02-20 Function与Object的关系

作者: FConfidence | 来源:发表于2020-02-20 14:10 被阅读0次

    Function 与 Object的关系

    1. instanceof 运算原理

      //假设instanceof运算符左边是L,右边是R
      l instanceof R //instanceof运算时,通过判断L的原型链上是否存在R.prototype
      l.__proto__.__proto__ ..... === R.prototype ? //如果存在返回true 否则返回false
      

      instanceof 检测左侧实例的 proto 原型链上,是否存在右侧对象的 prototype 原型。

    2. 图解构造器Function和Object的关系

      Function instanceof Object;//true
      Object instanceof Function;//true
      
      image.png
    3. 当构造器Object和Function遇到instanceOf

      • 所有的构造器的 constructor 都指向 Function

      • Function 的 prototype 指向一个特殊匿名函数,而这个特殊匿名函数的 proto 指向 Object.prototype

    相关文章

      网友评论

          本文标题:2020-02-20 Function与Object的关系

          本文链接:https://www.haomeiwen.com/subject/hldxqhtx.html