Whether keywords should be allowed as names in function declarations

David-Sarah Hopwood david.hopwood at industrial-designers.co.uk
Tue Jan 20 20:26:44 PST 2009

Brendan Eich wrote:
> On Jan 20, 2009, at 2:09 PM, David-Sarah Hopwood wrote:
>> The costs are:
>> - preventing implementations from reporting errors when a keyword is
>>   used unintentionally. This is a significant cost, especially for new
>>   programmers who may not be entirely familiar with the full keyword set.
> In practice it has not proven so for JS1.7 users, but who knows? You
> could be right that it would be a significant cost with more user
> testing. I wouldn't assert that it "is significant" yet without evidence.

Any benefit due to being able to give functions keyword names has to be
weighed against the cost of this lack of error reporting (and the
compatibility issue below). The benefit is low, so the cost doesn't
have to be particularly high, in order for the outcome to be against
making this change.

>> - programs that rely on this change will fail to work on some ES3
>>   implementations, when renaming the function would have been sufficient
>>   to allow them to work (if there is no other reliance on ES3.1).
> This says the spec should not allow extensions that add
> keyword-unreserving contexts. I'm sure you agree ;-).

I didn't say that this was a sufficient cost by itself to preclude such
extensions. In the case of allowing property names to be keywords, for
instance, we have a greater benefit because both the definition (in
object literals) and its use (in member expressions) can be allowed.

Nevertheless, this *is* a significant compatibility/interoperability cost.
IE7 doesn't appear to allow any keyword as a property name in either
object literals or member expressions, for instance, so it will be a
while before the ability to do this in ES3.1 is actually useful on the
web [*]. That's a consideration for any extension, but more so for
extensions that don't add any expressiveness to the language, and that
a program could have avoided with a simple local renaming.

[*] User adoption of new IE versions seems painfully slow:
    The only way I see that improving is if Microsoft change
    their browser upgrade policy.

David-Sarah Hopwood

More information about the Es-discuss mailing list