Module Pattern in JavaScript

In JavaScript, code encapsulation can be achieved using Modules Patterns. In addition, it is used to create private and public properties. There are various ways a module pattern can be implemented. In this article, we will learn to create a module pattern in ES5. Before we go ahead and start looking into the implementation of the module pattern, here are some of the benefits:

Freeze the scoping.
Code encapsulation.
Creating private or public scope.
Creating a namespace.
Creating public and private encapsulation.

We can implement a module pattern using JavaScript Object Literals and Immediately-Invoked function expressions. Just to refresh your memory, an object literal will look like the below listing:

Link: https://dzone.com/articles/module-pattern-in-javascript?utm_medium=feed&utm_source=feedpress.me&utm_campaign=Feed%3A+dzone%2Fwebdev