This function ("ns") allows you to not care about order
of JavaScript files during concatenation.
All you need is to wrap code of each file to ns()
call,
and access other modules via ns()
too.
Example:
ns.initAll()
ns('greeting-string', function(exports, module) {
module.exports = 'Hello world!';
});
ns('app', function(exports, module) {
var greeting = ns('greeting-string');
var showPopup = ns('popup').showPopup;
showPopup(greeting);
});
ns('popup', function(exports, module) {
exports.showPopup = function(content) {
alert(content);
};
});
# You also need to require some entry module
# at the end (when all modules defined) to run initializations chain
ns('app');
# Or you can initialize all modules
ns.initAll();
Disclaimer: it not some RequireJS alternative as it don't dynamically loads modules or something, it just handles initialization order when all javascript is already loaded somehow (for example concatenated to one file)
Blog post (russian): http://pozadi.github.io/2014/02/13/ns.html