My goal is to have my js organized into multiple files that are lazy loaded but have one namespace.
For example:
SO.global (global.js) SO.global.registration (registration.js) <- load
var SO = function(){
var CONSTANT = 'Z';
function createX(){
alert("create X");
}
function getY(){
alert("get Y");
}
return{
create:createX,
get:getY
}
}();
//SO.createX();
//SO.getY();
VS.
var SO = (function() {
var CONSTANT = 'Z';
function createX(){
alert("create X");
}
function getY(){
alert("get Y");
}
return {
create:createX,
get:getY
}
} ());
Have you considered Require.JS? It attempts to provide the following solution:
Require.JS implements the Module/Asynchronous Definition spec defined by Common.JS
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With