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: Wed, 15 Aug 2012 11:16:21 -0400
Message-ID: <502BBD45.9060601@mit.edu>
To: Axel Rauschmayer <axel@rauschma.de>
CC: Brandon Benvie <brandon@brandonbenvie.com>, public-script-coord@w3.org, Brendan Eich <brendan@mozilla.com>, es-discuss@mozilla.org
On 8/15/12 3:48 AM, Axel Rauschmayer wrote:
> In FF 14, Iím getting the following results (if there is an element
> whose ID is "foo"):
>
>      $ "foo" in window
>      false
>      $ foo
>      ReferenceError: foo is not defined

This is an artifact of how the repl you're using (presumably the Web 
Console in Firefox) is implemented.  In particular, if you're using the 
Web Console its global is NOT the window, which allows you to declare 
variables visible in the repl but not leaking to the web page.  But it 
leads to some weird artifacts with the global scope polluter, since 
there isn't one here, really.

In a web page, the behavior is different, as you can test by using an 
actual <script> tag.


> That looks like what you described: The Global Scope Polluter
> auto-creates foo after the read access (*). However, (**) puzzles me: A
> getter for foo seems to be called (as a warning is displayed), but it
> returns `undefined`. How come?

Because you're testing in a somewhat bizarre environment.

> Also interesting: window instanceof EventTarget holds,
> but EventTarget.prototype is not in protos(window)

Yes, indeed.  Host objects can do some interesting things with 
instanceof.  ;)  Again, this will be fixed once we move Window to WebIDL.

-Boris
Received on Wednesday, 15 August 2012 15:17:06 UTC

This archive was generated by hypermail 2.3.1 : Wednesday, 8 May 2013 19:30:07 UTC