Just add an object to the global namespace, assign your object literals or functions to that namespace.
window.PROJECT = {};
(function($,window,undefined) {
var A = {
init : function() { ... }
}
window.PROJECT.A = A;
})(jQuery, window);
PROJECT.A.init();
Alternatively you could just return the values from the modules to the PROJECT object.
window.PROJECT = {};
PROJECT.A = (function($, window, undefined) {
var A = {
init : function() { ... }
}
return A;
})(jQuery,window);
Again, you could just return an object to a global variable.
var PROJECT = (function($, window, undefined) {
var A = {
init : function() { ... }
}
var B = {
init : function() { ... }
}
return { A : A, B : B };
})(jQuery,window);
Additional based on previous answer mentioned by the OP, extending a global namespaced object. This is actually achieved already by the previous answer.
var PROJECT = (function(window, undefined) {
// Private var
var container,
// Class constructor
Example = function() {
}
Example.prototype = {
},
// Object literal
A = {
init : function() {
container = new Example();
}
// Expose or reflect other methods using private instance of Example
}
return { A : A };
})(window);
To extend PROJECT further do as the previous example demonstrated
(function(window, PROJECT, undefined) {
// Private vars
...
// Any other non exposed code
...
PROJECT.B = {
init : function() { ... }
}
// Make sure PROJECT is attached to window if it is empty object
if (typeof window.PROJECT === 'undefined')
window.PROJECT = PROJECT;
})(window, window.PROJECT || {});