When referencing a property defined within an object literal from within the same object literal, it is not possible. The properties are only assigned to the variable after the entire object literal has been evaluated. Therefore, you cannot reference properties of the variable within the object literal itself.
If you assign an object literal to a variable like this:
var data = { ... };
you will not be able to use the reference data
inside the object literal. This is because at the time of evaluation, data
is still undefined. It is only after the object literal has been fully parsed and evaluated that the Object value is created and assigned to data
.
var data = {
x: 456,
y: data.x // this will throw an error as "data" is undefined
};
data.y = data.x; // this will work fine