Module And Revealing Module Design Patterns In Javascript
Hello everybody,
today I want to propose you interesting comparison of two design patterns in javascript. As you probably know, javascript doesn't have idea of public and private members. So in order to implement them some tricks are used. That is module and "revealing module".
Take a look at samples of them:
Module |
Revealing module |
var md = ( function(){ var privateMember = “private”; return { publicMember : “publicMember” }; } )(); |
var md = ( function(){ var privateMember = “private”; var publicMember = “publicMember”; return { publicMember : “publicMember” }; } )(); |
The difference is where are members declared. In module all private members are declared inside of the function, and public members inside of return object. While revealing module has all of it's members declared inside of the function, and then returned only public members.
One of the common critisizm of revealing module pattern is challenge in distinguishing from declaration which member is public and which private. One of the common conventions is to prefix private members with prefix _. For example
var md = ( function(){
var _privateMember = “private”;
var publicMember = “publicMember”;
return {
publicMember : “publicMember”
};
}
)();
Just as JavaScript design patterns like the Module and Revealing Module help you structure and optimize your code, Acumatica’s flexibility allows you to tailor your ERP system to fit your unique business needs. If you’re looking to customize Acumatica to unlock its full potential, we’re here to help! Leave us a customization request today, and let’s build a solution that works as seamlessly as your code. Your ideal ERP customization is just a click away—get started now!