"var" declarations shadowing properties from Window.prototype

Brendan Eich brendan at mozilla.com
Sat Aug 11 19:20:46 PDT 2012

Cameron McCormack wrote:
> Jonas Sicking:
>>> Webkit also puts attributes on objects for non-globals, but I'm not
>>> promoting that behavior. Nor do I know of any benefits regarding web
>>> compatibility that comes with that behavior.
> Brendan Eich:
>> Ok, that's what I was getting at. It may be that this is just historical
>> consistency for all objects, no global exception, but sounds like we are
>> agreeing that the global object needs an exception ("own" promotion of
>> attributes and methods) in WebIDL.
> Before ES5 was out, Web IDL put properties for IDL attributes on 
> instances, exposed via special [[Get]] and [[Put]] behaviour.  That 
> was pretty much what implementations were doing.

Not all. Gecko had both custom [[Get]] and [[Put]] (ES3 internal method 
names) and accessors masquerading as data properties, on prototypes.

>   Once ES5 standardised accessor properties, we had the opportunity to 
> make IDL attributes less magical -- which was argued for pretty 
> strongly by TC39 folks, before Proxies came along.

I'm on TC39 and I argued more pragmatically, since at least Gecko had 
(masquerading) accessors on prototypes. I am leery of a-priori "cleaner 
= better = right" thinking, especially given web compatibility.

>   Now perhaps I didn't consider closely enough the possibility of this 
> being a breaking change (especially on the global object), but it 
> seemed everyone was happy enough with moving in that direction.  And I 
> think it's a cleaner model for shared properties with getter/setter 
> behaviour, anyway, and gives you the opportunity to monkeypatch them 
> that the special [[Get]] and [[Put]] behaviour couldn't.

Yes, that's a good thing and it goes back to how I did the DOM level 0 
in Netscape 2 -- with (masquerading) accessors and plain old method data 
properties on prototypes.

But the global object -- the window object then -- was quite a bit 
simpler in its prototype chain. We didn't have window implements 

> Which is to say that I think we should still push forward with 
> attributes-as-accessor-properties-on-prototypes at least for objects 
> other than the global object.

Agreed. Jonas and I are talking about an exception for the global 
object. It's the one on the scope chain. Well, other DOM objects are on 
scope chains of attribute-expressed event handlers. But such event 
handlers do not have any problem with var aliasing or shadowing a 
scope-object's properties (own or inherited).

The global object is the exception.


More information about the es-discuss mailing list