关于组合方法基继承
来源:3-13 面向对象(二)

百兽凯多00
2017-08-13
function Parent4 () {
this.name = 'parent4';
this.play = [1, 2, 3];
}
function Child4 () {
Parent4.call(this);
this.type = 'child4';
}
Child4.prototype = Parent4.prototype;
var s5 = new Child4();
var s6 = new Child4();
console.log(s5, s6);
console.log(s5 instanceof Child4, s5 instanceof Parent4);
console.log(s5.constructor);
老师,最后这里得到s5的构造函数不应该是 s5.__proto__.constructor 吗,为什么s5.constructor也可以呢
2回答
-
假凤眼
2018-03-03
我认为是s5里没有constructor属性,然后顺着__proto__向上找,找到s5的构造函数的原型对象,原型对象里有constructor属性,s5.__proto__.constructor===s5.constructor了。
00 -
JTR354
2017-08-13
s5.__protp__ === Child4.prototype
s5.__proto__.constructor === Child4.prototype.constructor
s5.constructor === Child4.prototype.constructor
所以,s5.constructor === s5.__proto__.constructor
我是这样想的,请老师指点.
042017-08-13
相似问题