"var" declarations shadowing properties from Window.prototype

Axel Rauschmayer axel at rauschma.de
Wed Aug 15 00:48:25 PDT 2012


> That's basically what the Global Scope Polluter does.  That's certainly how I plan to implement it in Gecko in the WebIDL bindings: Window.prototype.__proto__ will be a proxy which will do all the weird stuff the GSP has to do.


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
    $ window.foo  // (*)
    [object HTMLDivElement]
    Element referenced by ID/NAME in the global scope. Use W3C standard document.getElementById() instead.
    $ foo  // (**)
    undefined
    Element referenced by ID/NAME in the global scope. Use W3C standard document.getElementById() instead. @ Web Console:1
    $ "foo" in window
    true

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?

Also interesting: window instanceof EventTarget holds, but EventTarget.prototype is not in protos(window), an array created by:
    function protos(obj) {
        var chain = [];
        while (obj) {
            chain.push(obj);
            obj = Object.getPrototypeOf(obj);
        }
        return chain;
    }

Axel

-- 
Dr. Axel Rauschmayer
axel at rauschma.de

home: rauschma.de
twitter: twitter.com/rauschma
blog: 2ality.com

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20120815/538e622f/attachment-0001.html>


More information about the es-discuss mailing list