js Change variable will affect to original variable
I am sorry I do not know how to explain, but the situation is like this
example.
After I instant a new function c, and change the value this.i will
directly affect to a.
How can I solve this issue?? I do no know change this.i will affect to a.
http://jsbin.com/iPIkomu/1/edit
var a = { c: 1 };
var b = function(){
this.i = a;
this.i.c = 2;
};
var c = function(){
this.i = a;
alert(this.i.c);
};
c.prototype.set = function(){
this.i.c = 4;
alert(a.c);
};
d =new c();
d.set();
No comments:
Post a Comment