关于 __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
本想把生活活成一首诗, 时而优雅 , 时而豪放 , 结果活成了一首歌 , 时而不靠谱 , 时而不着调