Accessing submodules methods from main module?
up vote
0
down vote
favorite
What is the best practise in Javascript, if any, to access submodules methods from the main module?
We need to enlarge the project and want to hierarchize the modules right from the beginning, and thus be sure that things get done nice and neat right from the start. Our project was large, and as we are not pros we didn't use modules nor singletons, we put all the functions into global scope (I know now, it's a mess), and now we are facing a huge burden to reorganize everything. So, apologies if it's newbie question, but before allocating many men-hours, we want to be sure everything follows the best practises.
Is this approach correct and within best practises?
//in file Module.js
var Module = (function() {
//shall I put something here, to inform others about a submodule?
this.Utils = (function(){})();
function B() {
console.log("Module: B");
// accessing submodule public methods
// by name or this?
Module.Utils.C();
this.Utils.C();
};
return {
B: B
};
})();
//in file Utils.js
Module.Utils = (function() {
function C() {
console.log("Module.Utils: C");
};
return {
C: C
}
})();
(function(){
Module.B();
})();
javascript design-patterns module
add a comment |
up vote
0
down vote
favorite
What is the best practise in Javascript, if any, to access submodules methods from the main module?
We need to enlarge the project and want to hierarchize the modules right from the beginning, and thus be sure that things get done nice and neat right from the start. Our project was large, and as we are not pros we didn't use modules nor singletons, we put all the functions into global scope (I know now, it's a mess), and now we are facing a huge burden to reorganize everything. So, apologies if it's newbie question, but before allocating many men-hours, we want to be sure everything follows the best practises.
Is this approach correct and within best practises?
//in file Module.js
var Module = (function() {
//shall I put something here, to inform others about a submodule?
this.Utils = (function(){})();
function B() {
console.log("Module: B");
// accessing submodule public methods
// by name or this?
Module.Utils.C();
this.Utils.C();
};
return {
B: B
};
})();
//in file Utils.js
Module.Utils = (function() {
function C() {
console.log("Module.Utils: C");
};
return {
C: C
}
})();
(function(){
Module.B();
})();
javascript design-patterns module
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
What is the best practise in Javascript, if any, to access submodules methods from the main module?
We need to enlarge the project and want to hierarchize the modules right from the beginning, and thus be sure that things get done nice and neat right from the start. Our project was large, and as we are not pros we didn't use modules nor singletons, we put all the functions into global scope (I know now, it's a mess), and now we are facing a huge burden to reorganize everything. So, apologies if it's newbie question, but before allocating many men-hours, we want to be sure everything follows the best practises.
Is this approach correct and within best practises?
//in file Module.js
var Module = (function() {
//shall I put something here, to inform others about a submodule?
this.Utils = (function(){})();
function B() {
console.log("Module: B");
// accessing submodule public methods
// by name or this?
Module.Utils.C();
this.Utils.C();
};
return {
B: B
};
})();
//in file Utils.js
Module.Utils = (function() {
function C() {
console.log("Module.Utils: C");
};
return {
C: C
}
})();
(function(){
Module.B();
})();
javascript design-patterns module
What is the best practise in Javascript, if any, to access submodules methods from the main module?
We need to enlarge the project and want to hierarchize the modules right from the beginning, and thus be sure that things get done nice and neat right from the start. Our project was large, and as we are not pros we didn't use modules nor singletons, we put all the functions into global scope (I know now, it's a mess), and now we are facing a huge burden to reorganize everything. So, apologies if it's newbie question, but before allocating many men-hours, we want to be sure everything follows the best practises.
Is this approach correct and within best practises?
//in file Module.js
var Module = (function() {
//shall I put something here, to inform others about a submodule?
this.Utils = (function(){})();
function B() {
console.log("Module: B");
// accessing submodule public methods
// by name or this?
Module.Utils.C();
this.Utils.C();
};
return {
B: B
};
})();
//in file Utils.js
Module.Utils = (function() {
function C() {
console.log("Module.Utils: C");
};
return {
C: C
}
})();
(function(){
Module.B();
})();
//in file Module.js
var Module = (function() {
//shall I put something here, to inform others about a submodule?
this.Utils = (function(){})();
function B() {
console.log("Module: B");
// accessing submodule public methods
// by name or this?
Module.Utils.C();
this.Utils.C();
};
return {
B: B
};
})();
//in file Utils.js
Module.Utils = (function() {
function C() {
console.log("Module.Utils: C");
};
return {
C: C
}
})();
(function(){
Module.B();
})();
//in file Module.js
var Module = (function() {
//shall I put something here, to inform others about a submodule?
this.Utils = (function(){})();
function B() {
console.log("Module: B");
// accessing submodule public methods
// by name or this?
Module.Utils.C();
this.Utils.C();
};
return {
B: B
};
})();
//in file Utils.js
Module.Utils = (function() {
function C() {
console.log("Module.Utils: C");
};
return {
C: C
}
})();
(function(){
Module.B();
})();
javascript design-patterns module
javascript design-patterns module
asked Nov 19 at 13:14
João Pimentel Ferreira
3,69112126
3,69112126
add a comment |
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53375440%2faccessing-submodules-methods-from-main-module%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown