The Revealing Module pattern is the commonalty used design pattern which is easy to use and understand. This pattern define all of our functions and variables in the private scope and it return an object with pointers to the private functionality we wished to reveal as public.
In this way we can expose all those properties which we wish to make them public. The pattern can also be used to reveal private functions and properties with a more specific naming scheme if we would prefer.
It also makes it more clear at the end of the module which of our functions and variables may be accessed publicly which increase the readability.
This pattern allows us to actually invoke private functions via our public methods.
I have created an example which might clear the implementation.
This is a calculator class which is having the following methods.
- _privateFunction() // private function
2. sum() // public function
3. mul() // public function
4. divide() // public function
We can manipulate the operations with passing variables in constructor and getting the results accordingly.