varSingletontester = (function () { //parameters: A collection of parameters passed to a singleton functionSingleton (args) {//set the args variable to the received parameter or null (if not provided) varargs = args | | {}; //set the name parameter This. Name = ' Singletontester '; //set the value of the Pointx This. Pointx = Args.pointx | | 6;//taken from the received parameter, or set to the default value //set the value of the pointy This. Pointy = Args.pointy | | 10; } //Instance Container varinstance; var_static ={name:' Singletontester ', //methods to get instances //returns an instance of singletonGetInstance:function(args) {if(Instance = = =undefined) {Instance=NewSingleton (args); } returninstance; } }; return_static;}) ();varSingletontest = Singletontester.getinstance ({pointx:5}); Console.log (SINGLETONTEST.POINTX); //Output 5
201508181508_ best practices for JavaScript singleton mode (from Uncle Tom)