Exposing Moment
************************************/
- function makeGlobal() {
+ function makeGlobal(deprecate) {
+ var warned = false, local_moment = moment;
/*global ender:false */
- if (typeof ender === 'undefined') {
- // here, `this` means `window` in the browser, or `global` on the server
- // add `moment` as a global object via a string identifier,
- // for Closure Compiler "advanced" mode
+ if (typeof ender !== 'undefined') {
+ return;
+ }
+ // here, `this` means `window` in the browser, or `global` on the server
+ // add `moment` as a global object via a string identifier,
+ // for Closure Compiler "advanced" mode
+ if (deprecate) {
+ this.moment = function () {
+ if (!warned && console && console.warn) {
+ warned = true;
+ console.warn(
+ "Accessing Moment through the global scope is " +
+ "deprecated, and will be removed in an upcoming " +
+ "release.");
+ }
+ local_moment.apply(null, arguments);
+ };
+ } else {
this['moment'] = moment;
}
}
// CommonJS module is defined
if (hasModule) {
module.exports = moment;
- makeGlobal();
+ makeGlobal(true);
} else if (typeof define === "function" && define.amd) {
define("moment", function (require, exports, module) {
if (module.config().noGlobal !== true) {
- makeGlobal();
+ // If user provided noGlobal, he is aware of global
+ makeGlobal(module.config().noGlobal === undefined);
}
return moment;