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:27:24 -0700
Message-ID: <5027E77C.7000807@mozilla.com>
To: Boris Zbarsky <bzbarsky@MIT.EDU>
CC: Jonas Sicking <jonas@sicking.cc>, es-discuss@mozilla.org, public-script-coord@w3.org
Boris Zbarsky wrote:
> On 8/10/12 9:00 PM, Jonas Sicking wrote:
>> One potential solution that I think we should keep in mind is to
>> declare that WebIDL properties *on global objects* doesn't go on the
>> prototype chain, but rather on the global objects themselves.
> ...
>> It also has the advantage that Chrome already does this
> Chrome does this for some properties (attributes) but not others 
> (operations).
> I assume you just meant to do this for attributes?  Those are the only 
> cases in which var would call setters, obviously.
> The var shadowing issue is an issue for operations too, of course, but 
> it sounds like that's being solved on the ES side.

Not sure how it is solved if the JS programmer uses 'var'. Using 
'function' will shadow any prototype method (operation) of the same 
name, but then there's no object detection.

IOW, I think your requestAnimationFrame var+object-detection example is 
a good one. No difference in principle from the indexedDB case, and 
possibly only just luck that it has not bitten yet.

> I can live with putting attributes directly on the global.  If we ever 
> add an attribute to EventTarget that will be a little weird because 
> hooking the getter or setter on EventTarget.prototype will affect all 
> event targets _except_ the global, but that's life. 

Is there a WebIDL style guide for helping decide when and where to use 
attributes, or avoid them?

Received on Sunday, 12 August 2012 17:27:56 UTC

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