Possible Duplicate:
Self-references in object literal declarations
Hey Guys,
i have a small question regarding JavaScript Objects.
I have the following Object in JavaScript:
var CONFIG = {
MAIN_URL: 'http://www.test.us',
MAIN_COLOR: '#fff'
}
now i want to declare an object with another object prefixed:
var CONFIG = {
MAIN_URL: 'http://www.test.us',
LOGIN_URL: MAIN_URL+'/login', // <- this one!
MAIN_COLOR: '#fff'
}
how do i do that?
I have tried with this.MAIN_URL, CONFIG[MAIN_URL], CONFIG.MAIN_URL – but nothing works?!?!
Thanks,
Sascha
You can’t do that in an object initializer. Instead, do something like this: