From: Lucas Sanders Date: Mon, 22 Dec 2014 14:40:13 +0000 (-0500) Subject: Add globalScope hack to more reliably distinguish Node vs browser X-Git-Tag: 2.9.0~29^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F2117%2Fhead;p=thirdparty%2Fmoment.git Add globalScope hack to more reliably distinguish Node vs browser See #2092: browser-based apps that have DOM nodes with the id "global" were being detected as Node apps for purposes of assigning moment to the runtime's global namespace. This change is intended to fix that issue for most practical use cases, hopefully without breaking anyone's existing usage. Algorithm: If `global` is not defined, then we want to use `window`. If `global` is defined but `window` is not, then we want to use `global`. If both `global` and `window` are defined, then we want to assign to `global` if `window === global.window` -- otherwise we assume that `global === window.global`, in which case we want to assign to `window`. --- diff --git a/moment.js b/moment.js index 85e190d4a..10565a892 100644 --- a/moment.js +++ b/moment.js @@ -12,7 +12,7 @@ var moment, VERSION = '2.8.4', // the global-scope this is NOT the global object in Node.js - globalScope = typeof global !== 'undefined' ? global : this, + globalScope = (typeof global !== 'undefined' && (typeof window === 'undefined' || window === global.window)) ? global : this, oldGlobalMoment, round = Math.round, hasOwnProperty = Object.prototype.hasOwnProperty,