Subj : Re: new operator and call operator To : netscape.public.mozilla.jseng From : =?ISO-8859-1?Q?Georg_Maa=DF?= Date : Sat Mar 29 2003 07:28 am Thank you for that many useful information about misunderstood details. Waldemar Horwat wrote: > That is also a new operator. The parentheses and any contained > arguments are part of the new operator. This follows from the grammar > in ECMA 262 Edition 3, section 11.2. > >> Are there two new operators? > > > You can think of it as either two operators or one with an optional > argument list. > >> new FUNCTION >> and >> new FUNCTION (OPERANDLIST) >> where OPERANDLIST is used as arguments for the constructor function? >> >> I ask this for correctly documenting the language. Should I speak >> about two new operator variation or should I speak about a pure new >> operator and a combination of new operator and call operator? > > > It is definitely not a combination of a new operator and a call > operator. It took us a bit of trouble to make sure that the grammar in > section 11.2 disambiguates that. > >> Experiments with Selection in the Mozilla browser let me think it >> might be better to speak about two new operator variations, because >> >> Selection(); >> >> results in an error message, where >> >> new Selection(); >> and also >> new Selection; >> >> results in an exception. This gives me the idea, that there is no >> "call operator" in the second sample but the () must be a part of the >> new operator, which causes me to say, that there are two new >> operators, one with () and an other without, both doing the same. > > > Furthermore, if you follow the grammar in 11.2, you'll find that the > arguments are associated with the closest unmatched 'new' just like an > 'else' is associated with the closest unmatched 'if'. If there are no > more unmatched 'new' tokens, then the arguments form a function call. > Here is a little food for thought: > > new a(b)(c) means (new a(b))(c) and not new (a(b))(c) or (new > a)(b)(c) > > new new a(b) means new (new a(b)) > > new new a(b)(c) means new (new a(b))(c) > > new new a(b)(c)(d) means (new (new a(b))(c))(d) > > new a.b means new (a.b) and not (new a).b > > new a[b] means new (a[b]) and not (new a)[b] > > new a++ means (new a)++ and not new (a++) > > Waldemar > -- Georg Maaß - bioshop.de D-93466 Chamerau, Roßbergweg 42 JavaScript, C++ Engineering - The ultimative DHTML engine: http://gml-modul.sourceforge.net - http://sourceforge.net/projects/gml-modul .