I am trying to understand this javascript variable referring to the problem. Here is a fiddle to demonstrate what I'm going to explain: http://jsfiddle.net/XpVb5/1/
I have an object that I want to define and call within the individual properties of the object.
var vals = {'something':1};
var buf = {'field1': vals, 'field2': vals};
Now I want to change the property somethingonly field1, so I would do this:
buf.field1.something = 0;
However, this property will also change the property field2 something. I assume this is due to the way Javascript refers to variables in the process of defining a variable. But in any case, how can I get around this without explicitly calling {'something':0}every time I need to use it in the definition of a property; So:
var buf = {'field1': {'something':0}, 'field2': {'something':1}};
source
share