Object literal pattern, also known as modular pattern, is a way of organizing your javascript code. The biggest advantages of this approach is modularity, encapsulation and a clear, readable structure.
#javascript#object
// Declare an objectvarComponent={// Set required variables hereelement:document.querySelector('.component'),// Add your methodscomponentMethod:function(){// Do something},// Initialization methodinit:function(){// Set the requirements that need to be met to execute the methodif(Component.element){this.componentMethod();}}};// Finally check for elements and initialize the objectif(Component.element){Component.init();}