function F(){}
function A(){}
F.prototype = A;
console.log(new F()) //F {}
console.log(new F().prototype) //A {}
为什么new F().prototype 会是 A{}
new 不是应该把new F().__proto__指向F.prototype吗
继承看的云里雾里是否有什么好的文章推荐呢
function F(){}
function A(){}
F.prototype = A;
console.log(new F()) //F {}
console.log(new F().prototype) //A {}
为什么new F().prototype 会是 A{}
new 不是应该把new F().__proto__指向F.prototype吗
继承看的云里雾里是否有什么好的文章推荐呢
Chrome 下面和你的打印结果不太一样啊
function F(){}
function A(){}
F.prototype = A;
console.log(new F()) //F {}
console.log(new F().prototype) //Object {}
console.log(new F().__proto__) //A{}
10 回答11.1k 阅读
6 回答3k 阅读
5 回答4.8k 阅读✓ 已解决
4 回答3.1k 阅读✓ 已解决
2 回答2.6k 阅读✓ 已解决
3 回答2.3k 阅读✓ 已解决
3 回答2.1k 阅读✓ 已解决
new F().prototype === (new F()).prototype
而不是new (F().prototype)
,如果是new F.prototype
,才是new (F.prototype)
。new
是把new F().__proto__
指向F.prototype
,F.prototype = A;
你把F.prototype
指向了A
构造器了,所以是有prototype
属性的。new F().prototype === new F().__proto__.prototype