Subj : Re: new operator and call operator To : Georg Maaß From : waldemar@netscape.com (Waldemar Horwat) Date : Fri Mar 28 2003 11:08 pm At 7:28 AM +0100 3/26/03, Georg Maaß wrote: >Selection(); > ~~ >That is a call operator. > >new Selection; >~~~ >Here is a new operator. > >new Selection(); > ~~ >But what ist that? Is that a call operator to be used for an >internal call of the constructor function inside the new operation, >or is that a part of a second variation of the new operator? 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 .