Trying to implement singleton pattern in javascript following some tutorials. Just wondering if there is any other way to implement the same ?
var singleton = (function(){
              var getInstance; //private variable
              var createWidget = function(){
                         var todayDate = new Date(); //private
                         var addCSS = function(){
                            console.log('THis is my css function');
                         };
                         var getDropDownData = function(){
                            console.log('This is my getDropDownData function');
                         };
                         return {
                            getDropDownData : getDropDownData,
                            addCSS: addCSS 
                         };
              };
              return {
                    getInstance: function(){
                          if(!getInstance) {
                              getInstance = createWidget();
                          }
                          return getInstance;
                    }
              };
})();
var obj = singleton.getInstance();
Implementing it by running anonymous function at onLoad and assiging it to some variable. Can we implement it without running this function at onLoad ?
 
    