201508181508_ best practices for JavaScript singleton mode (from Uncle Tom)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.