I stumbled across this post: JavaScript’s Revealing Module Pattern. I would like to use this in my project.
Let’s imagine I have a function abc and I am calling that function in my main JavaScript file.
Does this pattern make things different? Can anyone show me a basic example of this pattern?
A small example:
in the anonymous function that is initiated to give
revealeda value,aandabcare private to that function. What the function returns is an object literal with anameproperty and aabcfnproperty, which is a reference to theabc function. Theabc functionuses the private variablea. This can all be done thanks to the use of closures (everything within the scope of a function can be referenced by everything else in that same function).Revealed usage: