在组合的情况下,子级的依然可以改变父级的prototype

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

慕侠4287760

2018-08-21


function Parent3(){
    this.name="parent3";
    this.id=[2,3,4]
}
function Child3(){
    this.child="child3"
    Parent3.call(this);

}
Parent3.prototype.say =function(){
    console.log("say something")
}
Parent3.prototype.test =[4,5,6];

Child3.prototype= new Parent3();
var child3 = new Child3();
child3.test.push(5);

var child3_1= new Child3();
//child3_1.id.push(5);

console.log(child3.test,child3_1.test);//都是4,5,6,5


写回答

1回答

快乐动起来呀

2018-08-22

没看懂你要问的点在哪

0
1
慕侠4287760
我的意思是parent.prototype.test属性被子类继承,但是我修改子类prototype.test属性,所有的子类的prototype.test都被修改了
2018-08-22
共1条回复

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

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

4836 学习 · 830 问题

查看课程