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 04:46 pm Thanks -- perfectly clear now. The reason I wondered is that I was not sure what the word 'literal' meant in context. In other words, I was not sure if the 'literal' form of an array, etc. was like a String literal, which is a primitive (passed by value, not by reference, etc). Thus I wondered if this supposed 'primitive' was used to construct an object on the fly. All said and done, I'll take some sugar with my Java(Script)! :) - Chris --- Brendan Eich wrote: > Christopher M. Balz wrote: > > 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). > > No, what you just wrote in parentheses is *not* what > I wrote, and it's > incorrect. > > You just wrote that > > var a = [1, 2, 3]; > for (var i = 0; i < 100; i++) > print(a); > > creates an Array object for each evaluation of the > variable a in the > actual argument expression passed to print. > > I said, and ECMA specifies, that the array > initialiser [1, 2, 3] is > shorthand for new Array(1, 2, 3). > > > > 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? > > I'm not sure why you thought each expression using a > variable that > happens to *refer* to an object created by an array > or object > initialiser re-evaluates the initialiser, but that > isn't how JS works, > and it doesn't make sense. For one thing, objects > are reference types, > so just evaluating a reference creates no new > object. > > /be > 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. .