mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-11 11:27:50 +00:00
Replace window var with root to better grab the global when using custom IIFEs.
Former-commit-id: f79834c6b53d692e85801d6258cd8beb35c776c2
This commit is contained in:
14
lodash.js
14
lodash.js
@@ -129,7 +129,7 @@
|
||||
};
|
||||
|
||||
/** Used as a reference to the global object */
|
||||
var window = this;
|
||||
var root = (objectTypes[typeof window] && window) || this;
|
||||
|
||||
/** Detect free variable `exports` */
|
||||
var freeExports = objectTypes[typeof exports] && exports;
|
||||
@@ -137,10 +137,10 @@
|
||||
/** Detect free variable `module` */
|
||||
var freeModule = objectTypes[typeof module] && module && module.exports == freeExports && module;
|
||||
|
||||
/** Detect free variable `global` from Node.js or Browserified code and use it as `window` */
|
||||
/** Detect free variable `global` from Node.js or Browserified code and use it as `root` */
|
||||
var freeGlobal = objectTypes[typeof global] && global;
|
||||
if (freeGlobal && (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal)) {
|
||||
window = freeGlobal;
|
||||
root = freeGlobal;
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
@@ -443,7 +443,7 @@
|
||||
* @static
|
||||
* @memberOf _
|
||||
* @category Utilities
|
||||
* @param {Object} [context=window] The context object.
|
||||
* @param {Object} [context=root] The context object.
|
||||
* @returns {Function} Returns the `lodash` function.
|
||||
*/
|
||||
function runInContext(context) {
|
||||
@@ -451,7 +451,7 @@
|
||||
// after built-in constructors like `Object`, for the creation of literals.
|
||||
// ES5 clears this up by stating that literals must use built-in constructors.
|
||||
// See http://es5.github.io/#x11.1.5.
|
||||
context = context ? _.defaults(window.Object(), context, _.pick(window, contextProps)) : window;
|
||||
context = context ? _.defaults(root.Object(), context, _.pick(root, contextProps)) : root;
|
||||
|
||||
/** Native constructor references */
|
||||
var Array = context.Array,
|
||||
@@ -6580,7 +6580,7 @@
|
||||
// case Lo-Dash was injected by a third-party script and not intended to be
|
||||
// loaded as a module. The global assignment can be reverted in the Lo-Dash
|
||||
// module via its `noConflict()` method.
|
||||
window._ = _;
|
||||
root._ = _;
|
||||
|
||||
// define as an anonymous module so, through path mapping, it can be
|
||||
// referenced as the "underscore" module
|
||||
@@ -6601,6 +6601,6 @@
|
||||
}
|
||||
else {
|
||||
// in a browser or Rhino
|
||||
window._ = _;
|
||||
root._ = _;
|
||||
}
|
||||
}.call(this));
|
||||
|
||||
Reference in New Issue
Block a user