javascript - What's the purpose of `root=...` code in Async library? -
there's snippet of code in async library:
if (typeof window == 'object' && === window) { root = window; } else if (typeof global == 'object' && === global) { root = global; } else { root = this; } is there reason code? why didn't author use root = this?
the first condition valid when this === window, root = window , root = this should equivalent. same thing in second condition, root = global should equivalent root = this.
am missing here?
not redundant, seems buggy.
just before snippet, there's :
// global on server, window in browser var root, previous_async; so goal assign root global object.
such library should coded work in strict mode (not in strict mode should @ least compliant). , in strict mode, context of iife execution undefined. code fail find root object in strict mode, both on node , in browser.
note there reliable ways find root object. standard 1 indirect call:
var root = (1,eval)('this');
Comments
Post a Comment