Subj : Re: Seeking clarification on effect of literal vs. object syntax. To : Christopher M. Balz From : Brendan Eich Date : Thu Aug 25 2005 03:45 pm Christopher M. Balz wrote: > I cannot find information on the interpretation of > variables defined to object values through a literal > syntax vs. the interpretation of variables defined via > constructor invocations. ECMA-262 Edition 3 11.1.4 and 11.1.5 seem reasonably clear and complete. > Specifically, does an array defined with literal > notation ('[]') remain a literal throughout program > execution, always having to be wrapped in an object on > the fly? There is no distinction in ECMA-262 or in implementations between a "literal" (really, an object or array initialiser) and an object that wraps it. The syntax causes an object to be created when the initialiser expression is evaluated. Contrast with RegExp literals, which create objects at compile time that correspond one-to-one with their source expressions, not with dynamic number of evaluations at runtime. If you mean "do array initialisers correspond to objects created once per initialiser expression, rather than once per evaluation of said expression", then the answer is "no". > If that is the case, that would be much slower than > defining the array with 'new Array()'. No, it would be about the same speed. > If that is not the case, then what was the rationale > behind providing the literal notation in the language? The syntax for array and object initialisers is sugar. Sugar is a fine thing some times; in tea and coffee, along with the tea leaves, coffee beans, and other spices, it spurred commerce around the world greatly ~500 years ago (caffeine helped too ;-). /be .