Regarding the reuse of different js writing styles, ask for help! ! ! ! !

  node.js, question

<div class=”box”></div>
<div class=”box2″></div>

Writing 1:

var module = (function(){
 var
 configMap = {},
 stateMap  = {},
 
 clearLocalStorage,
 saveLocalStorage,
 loadLocalStorage,
 bind,
 setJqueryMap,
 initModule
 ;
 
 clearLocalStorage = function(){
 };
 
 saveLocalStorage = function(){
 };
 
 loadLocalStorage = function(){
 };
 
 bind = function(){
 
 };
 
 setJqueryMap = function(){
 
 };
 
 initModule = function(){
 
 };
 
 return { initModule : initModule };
 })();
 
 module.initModule($('.box'));
 module.initModule($('.box2'));

Writing 2:

function AverageClass(){
 
 bracket
 AverageClass.prototype = {
 constructor : AverageClass,
 
 init : function(){},
 
 something : function(){
 
 bracket
 
 };
 
 var ager =  new AverageClass();
 var ager2 =  new AverageClass();
 
 ager.init($('.box'));
 ager2.init($('.box2'));

As for the above two writing styles, when operating multiple elements, the second one will not conflict, because each time is a different instance, but the first one will conflict. Is there any good way to save the first writing style? (i.e. let the module call in the first writing style become a different instance each time), hello everyone, I am the landlord, I modified the first writing style, is the creator mode still effective?

The first way is to use builder instead.
The second method is to create a common instance of the class

var module = {
 buildModule: function(el) {
 var configMap = {};
 var stateMap  = {};
 
 var clearLocalStorage = function() {
 };
 
 var saveLocalStorage = function() {
 };
 
 var loadLocalStorage = function() {
 };
 
 var initModule = function() {
 module.el = el;  //Examples of instance properties will not conflict with other instances.
 };
 
 var module = {
 //Method to export
 clearLocalStorage: clearLocalStorage,
 saveLocalStorage: saveLocalStorage,
 loadLocalStorage: loadLocalStorage,
 };
 
 initModule();  //If you don't need to call elsewhere, you can also leave the code here without the initModule function.
 
 return module;
 bracket
 };
 
 var module1 = module.buildModule($('.box'));
 var module2 = module.buildModule($('.box2'));