A reveal module is an immediately-invoked function expression that returns an object who's methods have closure over the enclosing functions variable scope.
Breaking down the definition, there are 3 key aspects to reveal-module.
-
The outer function is executed using a the IIFE syntax
(...)();
. This has the benefit of preventing any polution of the global scope with extra unnecessary varaibles. -
The outer function returns an object literal with functions as properties (methods). This is a factory that generates an object with methods (functions) and properties (variables).
-
Those methods create a closure over the scope so the retain (read, remember) the scope where they were defined. This effectively creates private properties and methods.