Possible Duplicate:
Self-references in object literal declarations
Can you call data from it's own json object?
I’m creating an object like this:
var lines = {
all: [ /* Array */ ],
current: this.all[1]
}
However the current: this.all[1] returns undefined. I know full well that I can create the current property like this:
var lines = {
all: [ /* Array */ ]
}
lines.current = lines.all[1];
But I think this is quite messy, especially when creating multiple properties that need to reference their own object.
I’ve tried using both
current: this.all[1](returnsundefined) andcurrent: lines.all[1](sayslinesdoesn’t exist)
How can I reference properties of the object I’m currently “in”? For instance, in my first example lines.current would be assigned the second element from lines.all.
There is just one other solution than the one you posted: