"use strict" VS setTimeout

Garrett Smith dhtmlkitchen at gmail.com
Sun Sep 7 11:59:32 PDT 2014

On 9/7/14, Mark Miller <erights at gmail.com> wrote:
> On Sun, Sep 7, 2014 at 11:27 AM, Domenic Denicola <
> domenic at domenicdenicola.com> wrote:
>>  I don't understand why this is any more surprising than any other
>> function that calls its callback with .call(something).
> The issue is what the something should be, and which choices for something
> are surprising for what APIs.
>> It doesn't matter whether the callback is strict or not; .call(window),
>> which is what the spec does, will override it.
> I don't understand what you're trying to say here. What will override what?
>> As far as I can see this issue has absolutely nothing to do with strict
>> vs. sloppy.
> As Andrea initially stated, this is a DOM-spec issue, not a JS issue, in
> that JS allows setTimeout to call the callback with WTF it wants. However,
> the purpose of setTimeout, etc, from the JS programmer's perspective, is to
> postpone some action to some future time. From this understanding, there's
> no reason to give the postponed action access to the global object. From a
> POLA perspective, there is thus strong reason not to.

If legacy compatibility is needed then setTimeout's callback function
must be called with the same window of setTimeout, just as with global

"use strict"
addEventListener("click", function(ev){
  console.log(this === window);

More information about the es-discuss mailing list