stefan22
8/29/2017 - 10:19 PM

Module Pattern JS - like a self executing function IISE ( Immediately Invoke Function Expression ) this is a module and we can easily add a

Module Pattern JS - like a self executing function IISE ( Immediately Invoke Function Expression )

this is a module and we can easily add another module with same var EX....variable that's hidden, and since each only runs on within its own module, they're completely independent from each other

(function(exports) {
  
      //hidden
      var EXCLAMATION_MARK_COUNT = 5;
  
      //public
      function exclaim(string) {
          return string + "!".repeat(EXCLAMATION_MARK_COUNT);
      }
  
      //making public
      exports.exclaim = exclaim;
  
})(this);


// run exclaim from outside fn expression
console.log(exclaim("hi"));

// try variable and it throws a ReferenceError
console.log(EXCLAMATION_MARK_COUNT);