"use strict" VS setTimeout

Garrett Smith dhtmlkitchen at gmail.com
Sun Sep 7 12:28:40 PDT 2014


On 9/7/14, Andrea Giammarchi <andrea.giammarchi at gmail.com> wrote:
> **implicitly fail** from a user point of view that used "use strict" to
> avoid receiving the global context in there ... I am not sure how much you
> want to turn it back to me but you are missing the point and I've not much
> else to say.
>

"use strict" doesn't avoid receiving the global object.

For function calls in strict code, "use strict" says the `this` value
is supplied by the caller, but if it isn't, the `this` value is
undefined.

The caller of the callback your example below was setTimeout. Method
setTimeout maintains a reference to the window and calls callback
function, `a`, with the window as the thisValue.

setTimeout(
  function a() {
    console.log(this);
  },
1);
-- 
Garrett
@xkit
ChordCycles.com
garretts.github.io


More information about the es-discuss mailing list