Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

The Module design pattern in javascript

var testModule = (function() {
  var counter = 0;
  return {
    incrementCounter: function() {
      return ++counter;
    },
    resetCounter: function() {
      counter = 0;
    }
  };
})();

// Usage:
testModule.incrementCounter();
testModule.resetCounter();
Source by dev.to #
 
PREVIOUS NEXT
Tagged: #The #Module #design #pattern #javascript
ADD COMMENT
Topic
Name
3+9 =