Skip to content

Revealing Module Pattern – Design Pattern

Posted in Education, and WhoCodeFirst

A variation of the module pattern is called the Revealing Module Pattern. The purpose is to maintain encapsulation and reveal certain variables and methods returned in an object literal. The direct implementation looks like this:

var Exposer = (function() {
  var privateVariable = 10;

  var privateMethod = function() {
    console.log('Inside a private method!');

  var methodToExpose = function() {
    console.log('This is a method I want to expose!');

  var otherMethodIWantToExpose = function() {

  return {
      first: methodToExpose,
      second: otherMethodIWantToExpose

Exposer.first();        // Output: This is a method I want to expose!
Exposer.second();       // Output: Inside a private method!
Exposer.methodToExpose; // undefined

An obvious disadvantage of it is unable to reference the private methods

Happy Learning! 😇

If you enjoyed this article, Get email updates (It’s Free)
Translate »