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

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

From: Boris Zbarsky <bzbarsky@MIT.EDU>
Date: Thu, 16 Aug 2012 02:13:24 -0400
Message-ID: <502C8F84.6070908@mit.edu>
To: Travis Leithead <travis.leithead@microsoft.com>
CC: Brendan Eich <brendan@mozilla.com>, Brandon Benvie <brandon@brandonbenvie.com>, "public-script-coord@w3.org" <public-script-coord@w3.org>, "es-discuss@mozilla.org" <es-discuss@mozilla.org>, Jonas Sicking <jonas@sicking.cc>
On 8/15/12 3:32 PM, Travis Leithead wrote:
> The problem: a few [high profile] sites are using a coding practice that uses feature detection of the following pattern:
>     var [standardized property name] = window.[standardized property name] || window.[implementation-specific property name] || [etc.]
> Firefox is affected by this problem (e.g., the result of the var declaration is undefined)
> Chrome is not affected by this problem because their var creation algorithm checks the prototype chain for an existing property name

And also because in Chrome IDL attributes are placed directly on the object.

> One side effect as I understand this, would be that:
>     var indexedDb = "test";
>     alert(indexedDb);
> would result in "test", and the original indexedDb property would be lost. Is this your understanding as well?

That's correct.

> Another side effect of this proposed change is that:
>     var onload = function(e) { ...}
> would actually assign the event handler (it does in Chrome today, not in Gecko/IE9/10).

Again, correct.

> I was curious just how "bad" the currently reported bug actually is. I ran a query looking for use of var indexedDb and var requestAnimationFrame across our web data index (which is unfortunately about a year old). jQuery uses the requestAnimationFrame a lot--but their use is contained to the jQuery scope closure. Modernizer was also using the var indexedDb technique, but Modernizer also runs in a scope closure and thus is not affected by this issue. In fact, any major library (and a lot of other sites that have adopted the "module pattern") won't be affected by this at all.

https://bugzilla.mozilla.org/show_bug.cgi?id=770844#c29 claims there is 
actual site breakage involved.  Presumably Jonas can give you more 
detailed info here; ccing him.

> Personally, I'd like to avoid making a change to IE in this regard if I can avoid it.

Are you planning to drop the prefixed name in IE?

Received on Thursday, 16 August 2012 06:13:58 UTC

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