使用原型链实现继承,会有一个问题,多个实例共享一个属性。
为了解决这个问题,我们使用构造函数来实现继承。
function A(){
this.people=['name','age',"sex"];
}
function B(){
A.call(this);
}
var x=new B();
x.people.push("play")
console.log(x.people);
var y=new B();
console.log(y.people);
运行结果,如下图所示: