mozilla

Revision 89150 of Reserved Words

  • Revision slug: Talk:JavaScript/Reference/Reserved_Words
  • Revision title: Reserved Words
  • Revision id: 89150
  • Created:
  • Creator: MarcelKorpel
  • Is current revision? Yes
  • Comment 3 words added, 3 words removed

Revision Content

>Mozilla will likely reserve these keywords in normal code in a future release, to conform to the specification ...

Is this really true?

I don't think so - ECMA-262 V5 states that reserved keywords may not be used as Identifiers which has a very strict definition:

Syntax
Identifier ::
    IdentifierName but not ReservedWord
    IdentifierName ::
        IdentifierStart IdentifierName IdentifierPart

It also states:

Two IdentifierName that are canonically equivalent according to the Unicode standard are not equal unless they are represented by the exact same sequence of code units

This is after replacement of any Unicode escape sequences and two Identifiers are not considered equal unless they match bitwise
Any reserved Keyword as described in ECMA-262 V5, 7.6.1 may not be used as Identifiers so:
var if; is invalid because it exactly matches a reserved keyword (var If; capitalized is ok)

Valid (simultaneous) Identifiers may/should be:

var myVar = 'string';
var myObj = {};
myObj.myVar = '';
myObj.myObj = null;
myObj.if = '';
myObj.typeof = 'Object';


myVar may coexist with myObj.myVar, myObj.myObj causes no confusion and myObj.typeof can't be mistaken for the reserved keyword typeof - the are not equal by definition

The same is true for any reserved word used as part of an Identifier - as long as they don't match there is no problem and should be allowed

I see no reason to impose unneeded rules for people to follow, especially when there is no other effect than a limitation of rational possibilities

> ... and to be consistent with other browsers

Opera and Safari are the only browsers that do not accept using reserved keywords as part of identifiers so it might be better if they change theirs to conform to the rest of the world?

Revision Source

<p>&gt;Mozilla will likely reserve these keywords in normal code in a future release, to conform to the specification ...</p>
<p>Is this really true?</p>
<p>I don't think so - ECMA-262 V5 states that reserved keywords may not be used as Identifiers which has a very strict definition:<br>
<br>
<code> Syntax<br>
Identifier ::<br>
    IdentifierName but not ReservedWord<br>
    IdentifierName ::<br>
        IdentifierStart IdentifierName IdentifierPart<br>
<br>
</code> It also states:<br>
<br>
<code> Two IdentifierName that are canonically equivalent according to the Unicode standard are not equal unless they are represented by the exact same sequence of code units<br>
</code> <br>
This is after replacement of any Unicode escape sequences and two Identifiers are not considered equal unless they match bitwise<br>
Any reserved Keyword as described in ECMA-262 V5, 7.6.1 may not be used as Identifiers so:<br>
<code>var if;</code> is invalid because it exactly matches a reserved keyword (<code>var If;</code> capitalized is ok)<br>
<br>
Valid (simultaneous) Identifiers may/should be:<br>
<br>
<code>var myVar = 'string';<br>
var myObj = {};<br>
myObj.myVar = '';<br>
myObj.myObj = null;<br>
myObj.if = '';<br>
myObj.typeof = 'Object';</code><br>
<br>
<code>myVar</code> may coexist with <code>myObj.myVar</code>, <code>myObj.myObj</code> causes no confusion and <code>myObj.typeof</code> can't be mistaken for the reserved keyword <code>typeof</code> - the are not equal by definition<br>
<br>
The same is true for any reserved word used as part of an Identifier - as long as they don't match there is no problem and should be allowed<br>
<br>
I see no reason to impose unneeded rules for people to follow, especially when there is no other effect than a limitation of rational possibilities</p>
<p>&gt; ... and to be consistent with other browsers</p>
<p>Opera and Safari are the only browsers that do not accept using reserved keywords as part of identifiers so it might be better if they change theirs to conform to the rest of the world?</p>
Revert to this revision