关于组合方法基继承

来源: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了。

0
0

JTR354

2017-08-13

s5.__protp__ === Child4.prototype

s5.__proto__.constructor === Child4.prototype.constructor

s5.constructor === Child4.prototype.constructor

所以,s5.constructor === s5.__proto__.constructor

我是这样想的,请老师指点.

0
4
JTR354
回复
我就看吓不说话
666,谢谢指点
2017-08-13
共4条回复

前端跳槽面试必备技巧 面试官全流程指导

一门让你能成功获取前端 Offer 的课程, 不只是技术,面试“技巧”也至关重要

4836 学习 · 830 问题

查看课程