In Node.js, inside the callback passed to setTimeout() , this appears to be tied to the timeoutObject returned by setTimeout() (both in strict mode and non-line mode!):
var timeoutObject = setTimeout(function () { console.log(this === timeoutObject); // true }, 0); var timeoutObject = setTimeout(function () { 'use strict'; console.log(this === timeoutObject); // true }, 0);
This is not the case in the browser, where this tied (as one would expect) to the global window object (or is undefined , in strict mode).
The documentation says nothing about this non-standard behavior.
Why is this?
kYuZz source share