[JS] ES5 Common Modular Pattern
ES5 Basic Module Pattern.
Place public functions in the return statement.
const moduleName = (function () {
const _private = "something";
const _privateFunction = function () {
return;
};
const publicFunction = function () {
return;
};
return {
publicFunction: publicFunction, // This function will expose
};
})();
// Example
moduleName._privateFunction(); // Invalid
moduleName.publicFunction(); // Valid
Comments