From my understanding, the concept of revealing module pattern can be demonstrated as follows:
SAMPLE #1
const iifeModulePattern = (function () {
const secretSeed = 999; // ← hidden
const logSecretCode = function(){console.log(secretSeed+1)};
return {methodForPublic : logSecretCode};
})();
iifeModulePattern.methodForPublic();
As far as I know, I believe I am on the right track. Now, my question is:
- Wouldn't Sample #2 accomplish the same goal?
- If yes, why is Sample #1 more popular than Sample #2?
- If not, what sets them apart?
SAMPLE #2
const modulePattern = () => {
const secretSeed = 999; // ← hidden
const logSecretCode = function(){console.log(secretSeed+1)};
return {methodForPublic : logSecretCode};
};
modulePattern().methodForPublic();
I want to clarify that these code snippets are only examples and not meant for storing actual sensitive information like passwords.