Possible Duplicate:
How can a Javascript object refer to values in itself?
Let’s say I have:
var myNamespace = {
_prop1: 'hello',
_prop2: _prop1 + ' you!'
};
I’m just now finding out that this will error on _prop2 at load.
I can’t understand why this doesn’t work, I’ve worked around it in my code but I would still like to understand.
When you try and set prop2 the object hasn’t initialised so the value of prop1 and mynamespace are both undefined.
There are a couple of ways to achieve what you want, one way would be to create prop2 as a function so it can dynamically get the value of prop1
Another way would be to set prop2 after myNamespace has been initialised