Garret for legacy we are good to go with `.call(undefined)` that will bring window in there but `addEventListener` is a different intent/operation than `setTimeout` plus you lways have `e.currentTarget` which is always preferable anyway since this will not produce what you expect:
```js addEventListener("click", {handleEvent: function(ev){ console.log(this === window); // nope }}); ``` Regards On Sun, Sep 7, 2014 at 7:59 PM, Garrett Smith <dhtmlkitc...@gmail.com> wrote: > On 9/7/14, Mark Miller <erig...@gmail.com> wrote: > > On Sun, Sep 7, 2014 at 11:27 AM, Domenic Denicola < > > dome...@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 > addEventListener. > > <script> > "use strict" > addEventListener("click", function(ev){ > console.log(this === window); > }); > </script> > -- > Garrett > @xkit > ChordCycles.com > garretts.github.io > _______________________________________________ > es-discuss mailing list > es-discuss@mozilla.org > https://mail.mozilla.org/listinfo/es-discuss >
_______________________________________________ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss