JavaScript version 1.2 introduces Object literals.
The object is created and returned by the expression. This would normally be assigned to a variable, which effectively names the object. It isn't the object class but it can be copied. Its class is still "Object".
Object literals can be nested so that the properties of the topmost object can in fact be object literals themselves.
The values assigned to the properties as the object is created can be derived by evaluating a JavaScript expression.
You can add as many properties as you care to but you must be careful to keep the nesting properly balanced.
The result is an object with the properties containing the values described in the literal expression.
// Create a simple object literal var simple = { prop:100 }; // Create a nested object literal var nested = { reference: { prop:100 } }; // Create a nested object literal with expression derived value var evaluated = { reference: { prop:(Math.random()*100) } };
See also: | Object constant, Object.constructor |
ECMA 262 edition 3 - section - 11.1.5
O'Reilly JavaScript Definitive Guide - page - 45
Prev | Home | Next |
Object inspector | Up | Object model |
JavaScript Programmer's Reference, Cliff Wootton Wrox Press (www.wrox.com) Join the Wrox JavaScript forum at p2p.wrox.com Please report problems to support@wrox.com © 2001 Wrox Press. All Rights Reserved. Terms and conditions. |