W3C home > Mailing lists > Public > public-script-coord@w3.org > January to March 2015

Global method calls

From: Domenic Denicola <d@domenic.me>
Date: Sun, 22 Feb 2015 21:03:37 +0000
To: "es-discuss@mozilla.org" <es-discuss@mozilla.org>
CC: "public-script-coord@w3.org" <public-script-coord@w3.org>
Message-ID: <CY1PR0501MB13697C2B1076CED62B15419FDF280@CY1PR0501MB1369.namprd05.prod.outlook.com>
(Cc'ing public-script-coord in case this answer gets more complicated in the presence of the window proxy/overriden this-in-global setup.)

Given code like

      addEventListener("foo", function () { });

Is this supposed to be an Invoke(current global, "addEventListener", <"foo", function () {}>)?

Or is it just a Call(addEventListener, undefined, <"foo", function () {}>)?

What about if I added "use strict"; to the top of the script?

My suspicion was Invoke, but then I came up with another example that threw me off:

    window.globalFunc = function () {
        console.log("this", this);

    "use strict";

This gives `undefined`. (The result is the same if I also prepend "use strict"; to the top of the first script.) That nudges me toward the Call answer.

But under the Call answer, my first example would be broken since the implementation of `addEventListener` would not have a sensible `this` to operate on.

Anyway, I'm clearly missing something. What is it, and where are the relevant parts of the spec?
Received on Sunday, 22 February 2015 21:04:07 UTC

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