"var" declarations shadowing properties from Window.prototype

Brendan Eich brendan at mozilla.com
Sun Aug 12 10:49:50 PDT 2012


Boris Zbarsky wrote:
> On 8/12/12 1:31 PM, Brendan Eich wrote:
>> There's still a problem for getter-less attributes including 
>> indexedDB, so

[setter-less]

>> something *still* has to change there!
>
> I'm not sure I follow this.  If indexedDB is on the global as an own 
> property, what issue remains with it?

A var indexedDB in global scope where the global object has such a 
get-only accessor will not clobber the existing property, but the 
var+obj-detection pattern initializes the variable:

   var indexedDb = ... || window.indexedDB;

and that will fail in strict mode (thanks, you point that out below):

js> void Object.defineProperty(this, 'foo', {get: function(){return 42}})
js> foo
42
js> var foo = 42
js> "use strict"; var foo = 43
typein:4: TypeError: setting a property that has only a getter

>> The global needs to be a flat object (only
>> implementation-specific magic protos along a chain ending in
>> Object.prototype).
>
> The magic from the global scope polluter isn't even impl-specific.

Right, HTML5 -- thanks to old IE :-|.

>> And we still need to be careful about writability (get-only indexedDB
>> point above).
>
> Ah, you meant setter-less above?

D'oh, yes.

> Only a problem in strict mode, right?

Right.

/be


More information about the es-discuss mailing list