Possible Duplicate:
Self-references in object literals / initializers
Can this be done? (obviously not in this syntax)
var a = {
b : 10,
c : this.b * 2 // returns 'undefined'
};
I have also tried
var a = {
b : 10,
c : a.b * 2 // throws error 'a is undefined'
};
and
var a = {
b : 10,
c : b * 2 // throws error 'b is undefined'
};
It makes sense to me that these values are undefined, I have not finished defining them. However it seems to me like there would be a solution to structuring a object like that and having c
be conditional on b