Revealing Module Pattern

by Santosh Thakur

JavaScript

var Exposer = (function() {
  var privateVariable = 10;
  var privateMethod = function() {
    console.log('The Value 1 > Inside a private method!');
    privateVariable++;
    console.log('The Value 2 > Inside a private method!', privateVariable);
  }
  var methodToExpose = function() {
    console.log('The Value 3 > This is a method I want to expose!');
  }
  var otherMethodIWantToExpose = function() {
    console.log('The Value 4  > This is a method I want to expose!');
    privateMethod();
  }

  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
//Exposer.privateMethod;