I’ve been running into a problem with a script that I’m writing. I’m trying to duplicate an object by assigning it to another variable, but it seems to be passing it by reference rather than assignment. Any changes the to new variable change the old variable as well and vice-versa. Here is a short script to illustrate what is going on:
[CODE]function obj() {
this.variable = true;
}
x = new obj();
y = x;
alert(x.variable);
y.variable = false;
alert(x.variable);
It will alert “true” and then alert “false” showing that x has changed even though I’ve only changed y. I want to be able to change them separately.
Does anyone know what’s going on and how to solve this problem?