function Parent() {
this.a = 1;
this.b = [1, 2, this.a];
this.c = { demo: 5 };
this.show = function () {
console.log(this.a , this.b , this.c.demo );
}
}
function Child() {
this.a = 2;
this.change = function () {
this.b.push(this.a);
this.a = this.b.length;
this.c.demo = this.a++;
}
}
Child.prototype = new Parent();
var parent = new Parent();
var child1 = new Child();
var child2 = new Child();
parent.show();
child1.show();
child2.show();
child1.change();
为什么运行change()的时候child1.show(),child2.show(),的数组也会改变呢(push的this.a)?谢谢!
凤凰求蛊
相关分类