I have following code. Why do all the three objects refer to the same array while the string variable is independent? How can I fix it without explicitly adding: function B(){this.arr = [];}
function A(){
this.text = "";
this.arr = [];
this.action = function(){
this.text+="z";
this.arr.push(1);
}
this.test = function(){
console.log(this.text+"|"+this.arr);
}
}
function B(){
}
B.prototype = new A();
B.prototype.constructor = B;
var B1 = new B();
var B2 = new B();
var B3 = new B();
B1.action();
B2.action();
B3.action();
B1.test(); //z|1,1,1
B2.test(); //z|1,1,1
B3.test(); //z|1,1,1