"var" declarations shadowing properties from Window.prototype
bzbarsky at MIT.EDU
Wed Aug 15 08:16:21 PDT 2012
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
> $ 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.
More information about the es-discuss