In the very simple code below I'm illustrating having a master 'App' object with 'Chat' & 'Posts' modules inside. Now, what I'm asking is, in my conscious effort to keep my components loosely coupled and modular, how I can use other functionality in the App object following the modular, decoupled pattern of JS web apps? Ie, imagine if I plucked the 'Chat' object out of the 'App' object and put it inside an 'App1' object, this code would break, so it's tightly coupled with the 'App' object. Can anyone offer any advice on decoupling my code below?
​var App = {
Utils: {
add: function(a,b){
return a + b;
}
},
Posts: {
},
Chat: {
init: function(){
console.log(App.Utils.add(1,2)); // 3
},
}
}
App.Chat.init();