For lack of a better title… Is it possible to do something like this in JSON?
var obj = {
a : 'a constant',
b : a + ' and b constant'
}
Update: Doesn’t work – this.a returns undefined I know this will work but it looks rather ugly and convoluted:
var obj = {
a : 'a constant',
b : (function(){ return this.a + ' and b constant'; })()
}
And here’s what I have currently:
var obj = {
a : 'a constant',
b : 'a constant and b constant'
}
I know of the other ways that some have commented upon and I sincerely thank them for responding. However, they don’t look simple or elegant. The only issue I have with my current implementation is that if value of ‘a’ ever gets updated, search-n-replace has to done in many places (I say many because there are more properties that derive from ‘a’) instead of one.
Found a potential solution:
Thanks everyone for their tips! Upvoting all good suggestions.