obsoleting the "new" keyword

Brendan Eich brendan at mozilla.com
Mon Jan 19 00:03:26 PST 2009

On Jan 18, 2009, at 10:23 PM, Mark Miller wrote:

> 2009/1/18 Brendan Eich <brendan at mozilla.com>:
>> The other unreserved context in JS1.7 and later is after the  
>> 'function'
>> keyword. Unambiguous, complementary, useful for some cases. It's  
>> easy to
>> tweak ES3.1's grammar to allow keywords in this context too.  
>> Thoughts?
> It would be surprising to be able to say "function if(x) {return x;}"
> but not "if(33);".

Surprising to a PL/1 fanboy :-P.

Seriously, if that is surprising, then is it surprising that

var obj = {if: 42};
with (obj)

doesn't work? Don't bust on 'with', the same issue arises in global  
code with 'this' or equivalent ('global', 'window').

> On property names, we symmetrically unreserve both
> the definition (by object literal) and the use (by ".").

Definition is just sugared assignment, in ES3 at any rate. You can't  

if = 4;

even though you can (in ES3.1 or JS1.7) say

this.if = 4;

at top level.

The best real-world example is when implemening something in JS that  
has to match an interface across a language bridge with a reasonable  
method name such as 'delete'. In such a case you could certainly use  
an object initialiser or assignment (doesn't matter which), but you  
couldn't give the function the intrinsic name 'delete'. Named  
functions have their uses, not so much for recursive calls as for  
better diagnostics and less inscrutable pretty-printing results.

Symmetry has less to do with any of this than utility. There are  
several symmetries or relations here ("definition", assignment,  
reference). Special-pleading for one kind of symmetry doesn't resolve  
the argument from utility.

No one outside of the PL/1 community wants 'var var = var;' or other  
such keywords in the unqualified reference sense to be possible. But  
we've agreed (based on precedent) to two out of the three contexts in  
which JS1.7 allows keywords to be used as identifiers. The use-case  
for the third, function names, is strong enough that we implemented  
it. I think it ought to be in 3.1, so I guess I'll put this on the f2f  


More information about the Es-discuss mailing list