W3C home > Mailing lists > Public > public-script-coord@w3.org > July to September 2012

Re: "var" declarations shadowing properties from Window.prototype

From: Brendan Eich <brendan@mozilla.com>
Date: Sun, 12 Aug 2012 10:31:11 -0700
Message-ID: <5027E85F.5040301@mozilla.com>
To: Boris Zbarsky <bzbarsky@MIT.EDU>
CC: Cameron McCormack <cam@mcc.id.au>, public-script-coord@w3.org, es-discuss@mozilla.org
Boris Zbarsky wrote:
> On 8/11/12 9:16 PM, Brendan Eich wrote:
>> As bz and others point out, the object detection w/ var pattern can
>> arise for operations, e.g. for requestAnimationFrame, using the same
>>    var requestAnimationFrame = window.mozRequestAnimationFrame || ... ||
>> window.requestAnimationFrame;
>> pattern. So WebIDL operations (JS methods) on the global would be
>> promoted to "own" too. They'd be configurable, if I recall correctly,
>> and either writable or replaceable. Do I have that right?
> This is unnecessary if we stick with the current var wording in 5.1.

Right. Unfortunately engines have shipped the erratum fix and it is 
helpful some times. We have a real dilemma. When var should shadow vs. 
not shadow depends on whether the detected property lives on the 
global's prototype chain. Thus the interest in moving everything down to 
be "own" properties on the global.

That way, function declarations clobber, and var leave alone. There's 
still a problem for getter-less attributes including indexedDB, so 
something *still* has to change there!

> If this _is_ done, that will mean hooking 
> EventTarget.prototype.addEventListener won't hook adds on the global, 
> which is a bit weird.

I think the primal sin (mine, again) is objects as scopes. But that 
can't be helped, so elaborating the global object's prototype chain, 
specifically to add expressiveness such as EventTarget monkeypatching, 
is going the wrong way. The global needs to be a flat object (only 
implementation-specific magic protos along a chain ending in 

And we still need to be careful about writability (get-only indexedDB 
point above).

Received on Sunday, 12 August 2012 17:31:42 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 17:14:07 UTC