Basically the code says everything. I have a variable x
with a css
property. I'm saving all the css
of x
into y
, and then I change the value of the y
's property. This change also affects x
, why? How to make it to only pass the value so that x
stays unchanged?
var x = {};
x.css = {height: 100, width: 100};
var y = {};
y.css = x.css;
y.css.height = 200;
console.log(x.css.height); //equals to 200 while it should be 100