mercredi 31 décembre 2014

How to change namespace in moment js?


I'm trying to change namespace for moment js. The script wrapped (function (undefined) {...}).call(this); I could pass namespace in call, however that breaks bower update compatibility (bower would override my change, and I could forget to keep files in sync). Can you suggest alternative solution?


Documentation suggest to use require.js to pass configuration options.http://ift.tt/1pjcgXN It's an additional script that I have to load. Is there alternative to require.js?


moment js has a makeGlobal function:



function makeGlobal(shouldDeprecate) {
/*global ender:false */
if (typeof ender !== 'undefined') {
return;
}
oldGlobalMoment = globalScope.moment;
if (shouldDeprecate) {
globalScope.moment = deprecate(
'Accessing Moment through the global scope is ' +
'deprecated, and will be removed in an upcoming ' +
'release.',
moment);
} else {
globalScope.cplex = {};
globalScope.cplex.moment = moment;
}
}


I combine and minify js with make. One solution that's not ideal:



//moment-init.js
var ender = undefined;
if(typeof moment !== 'undefined'){
var existingMomentJs = moment;
}
//load moment script
//moment-overrider.js
//updating namespace for moment js - abc namespace
var abc = {};
var ender = undefined;
abc.moment = moment;
if(typeof existingMomentJs !== 'undefined'){
moment = existingMomentJs;
}




Aucun commentaire:

Enregistrer un commentaire