组合继承的优化2

来源:3-13 面向对象(二)

慕的地3168188

2017-09-12

function Parent5(){

    this.name = 'parent5';

    this.play = [1,2,3];

}

function Child5(){

    Parent5.call(this);

    this.type = 'child5';

}

Child5.prototype = Object.create(Parent5.prototype);

var test1 = new Child5()

console.log(test1.__proto__) //Parent5, 并没有指向Child5


写回答

2回答

慕的地3168188

提问者

2017-09-12

test1.__proto__ === Child5.prototype //true

0
0

慕的地3168188

提问者

2017-09-12

是我没有看完视频,老师也讲到了需要手动指定constructor

Child5.prototype.constructor = Child5

没有疑问

0
0

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

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

4836 学习 · 830 问题

查看课程