my_blog icon indicating copy to clipboard operation
my_blog copied to clipboard

模拟new实现代码中,有几处有疑义

Open scarsu opened this issue 5 years ago • 2 comments
trafficstars

scarsu avatar Oct 16 '20 02:10 scarsu

第一处有什么问题呢?

sanyuan0704 avatar Oct 16 '20 06:10 sanyuan0704

实例的原型(即__proto__属性)应该指向构造函数的原型对象(即prototype),用obj.__proto__ = Object.create(ctor.prototype);是指向了一个新对象

new A().__proto__===A.prototype //true
newFactory(A).__proto__===A.prototype  // false
newFactory(A).__proto__.__proto__===A.prototype  // true

scarsu avatar Oct 16 '20 06:10 scarsu