Carl Danley

The Revealing Module Pattern

This pattern is the same concept as the module pattern in that it focuses on public & private methods. The only difference is that the revealing module pattern was engineered as a way to ensure that all methods and variables are kept private until they are explicitly exposed; usually through an object literal returned by the closure from which it's defined. Personally, I like this approach for vanilla JavaScript as it puts a clear emphasis on both the intent of the developer and the module itself.

"I've used this pattern on projects ranging from 100 to 100,000 lines of code." - Bob Holt

This article is part of a series called JavaScript Design Patterns.




This pattern can also be implemented using a privately shared cache (see Example 2 of the module pattern for an example.)

Additional Resources

Other Common JS Patterns

The Module Pattern
The Revealing Module Pattern
The Singleton Pattern
The Observer Pattern
The Mediator Pattern
The Prototype Pattern
The Facade Pattern
The Factory Pattern