From d898fcee75d38c3ffb00fd4dbaa41afa2e0305a0 Mon Sep 17 00:00:00 2001 From: jdalton Date: Wed, 4 Mar 2015 21:45:24 -0800 Subject: [PATCH] Simplify the `root` assignment. --- lodash.src.js | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/lodash.src.js b/lodash.src.js index 748fdaf7c..97981784d 100644 --- a/lodash.src.js +++ b/lodash.src.js @@ -259,30 +259,29 @@ '\u2029': 'u2029' }; - /** - * Used as a reference to the global object. - * - * The `this` value is used if it is the global object to avoid Greasemonkey's - * restricted `window` object, otherwise the `window` object is used. - */ - var root = (objectTypes[typeof window] && window !== (this && this.window)) ? window : this; - /** Detect free variable `exports`. */ var freeExports = objectTypes[typeof exports] && exports && !exports.nodeType && exports; /** Detect free variable `module`. */ var freeModule = objectTypes[typeof module] && module && !module.nodeType && module; - /** Detect free variable `global` from Node.js or Browserified code and use it as `root`. */ + /** Detect free variable `global` from Node.js. */ var freeGlobal = freeExports && freeModule && typeof global == 'object' && global; - if (freeGlobal && (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal || - (typeof freeGlobal.WorkerGlobalScope == 'function' && freeGlobal instanceof freeGlobal.WorkerGlobalScope))) { - root = freeGlobal; - } + + /** Detect free variable `window`. */ + var freeWindow = objectTypes[typeof window] && window; /** Detect the popular CommonJS extension `module.exports`. */ var moduleExports = freeModule && freeModule.exports === freeExports && freeExports; + /** + * Used as a reference to the global object. + * + * The `this` value is used if it is the global object to avoid Greasemonkey's + * restricted `window` object, otherwise the `window` object is used. + */ + var root = freeGlobal || ((freeWindow !== (this && this.window)) && freeWindow) || this; + /*--------------------------------------------------------------------------*/ /**