Subj : Re: Seeking clarification on effect of literal vs. object syntax. To : netscape.public.mozilla.jseng From : Christopher M. Balz Date : Fri Aug 26 2005 01:47 pm Thank you for your response. The ECMA-262 spec is quite clear about RegExps, so I read you that arrays and objects work the other way (a fresh object is created each time the variable holding the literal expression is evaluated). Wouldn't a program that had to constantly wrap array literal variables in objects run much slower than one that had made its arrays (for example) via the 'new Array()' constructor call? - Chris B. --- Brendan Eich wrote: > 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 > _______________________________________________ > mozilla-jseng mailing list > mozilla-jseng@mozilla.org > http://mail.mozilla.org/listinfo/mozilla-jseng > Christopher M Balz http://treelogic-swe.com 160 Lincoln Avenue, Palo Alto, CA 94301-2437, USA (h) 650.327.0367 / (w) (001) 408.376.4820 cbalz@andrew.cmu.edu christophermbalz@stanfordalumni.org chris@treelogic-swe.com ". . . / This Cabinet is formd of Gold / And Pearl & Crystal shining bright And within it opens into a World / . . . Another England there I saw / Another London with its Tower Another Thames & other Hills / And another pleasant Surrey Bower . . ." - from "The Crystal Cabinet", a poem by William Blake. .