In strict mode, it thismust be undefinedinside a non-method (function):
see http://jsfiddle.net/jfp06nc9/1/
showing thisisundefined
However, when used setTimeout, it is then thistied to window:
see http://jsfiddle.net/jfp06nc9/2/
and http://jsfiddle.net/jfp06nc9/3/
showing what this === windowreturns true.
so the function fnpassed in setTimeoutis not called as a function, but as a method, for example, window.fn()or fn.call(window)or (fn.bind(window))().
see http://jsfiddle.net/jfp06nc9/4/
showing the last 3 calls above, all will be displayed this === windowas true.
It's true? I cannot find any specifications, so please include this in your answer.
(jsfiddle is running in Chrome 46.0)
PS This question is NOT about what it is attached to this, but in loose mode it setTimeoutcan start fn(), but is thisattached to window. But in strict mode, if it setTimeoutreally starts it like fn(), then thisnow it should be undefinedinstead window, so there is a subtle difference that it seems that it setTimeoutstarts it (or arrange its launch) not how fn(), but howfn.call(window)
jsfiddle and code:
http://jsfiddle.net/jfp06nc9/7/
(function() {
"use strict";
setTimeout(function() {
"use strict";
console.log(this);
}, 1000);
}());
, , this undefined, window