关于 __proto__ constructor prototype 的理解(说人话)

<script>
      // constructor : 指向构造函数
      // prototype : 指向原型对象

      function Fn() {}
      const a = new Fn();

      // __proto__ : 指向构造函数的原型对象
      console.log(a.__proto__ === Fn.prototype); // true
      // 使用new关键字实例化的对象, 原型指向 undefined
      console.log(a.prototype); // undefined
      // constructor 指向把它构造出来的'对象'
      console.log(a.constructor === Fn); // true
      // a.constructor 指向 Fn
      console.log(a.constructor.prototype === a.__proto__); // true
    </script>

constructor: 指向构造函数

prototype: 指向原型对象

__proto__: 指向构造函数的原型对象

继承而来的东西, 自身没有原型对象, 指向undefined

posted @ 2022-02-22 09:58  深海里的星星i  阅读(42)  评论(1)    收藏  举报