Skip to content

Commit

Permalink
Merge pull request #1590 from ichernev/early-amd-global
Browse files Browse the repository at this point in the history
Set AMD global before module definition
  • Loading branch information
icambron committed Apr 4, 2014
2 parents e329d40 + 9e4938e commit 546fc09
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions moment.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
VERSION = "2.5.1",
// the global-scope this is NOT the global object in Node.js
globalScope = typeof global !== 'undefined' ? global : this,
oldGlobalMoment,
round = Math.round,
i,

Expand Down Expand Up @@ -2431,6 +2432,7 @@
if (typeof ender !== 'undefined') {
return;
}
oldGlobalMoment = globalScope.moment;
if (shouldDeprecate) {
globalScope.moment = deprecate(
"Accessing Moment through the global scope is " +
Expand All @@ -2448,13 +2450,14 @@
makeGlobal(true);
} else if (typeof define === "function" && define.amd) {
define("moment", function (require, exports, module) {
if (module.config && module.config() && module.config().noGlobal !== true) {
// If user provided noGlobal, he is aware of global
makeGlobal(module.config().noGlobal === undefined);
if (module.config && module.config() && module.config().noGlobal === true) {
// release the global variable
globalScope.moment = oldGlobalMoment;
}

return moment;
});
makeGlobal(true);
} else {
makeGlobal();
}
Expand Down

0 comments on commit 546fc09

Please sign in to comment.