Replace "new Function()"
Closed this issue · 2 comments
nervgh commented
Octane commented
this ≡ global
is just the top level scope inside a Node module, local to that module.
Function('return this')()
returns the general global scope, where the method setImmediate
is defined.
// inside a module:
typeof global.setImmediate // → 'undefined'
// but
typeof Function('return this')().setImmediate // → 'function'
I can rewrite the code like this:
var setImmediate = this.setImmediate || require('timers').setImmediate;
nervgh commented
Thanks!