javascript singleton question

前端 未结 10 2064
闹比i
闹比i 2020-12-12 20:08

I just read a few threads on the discussion of singleton design in javascript. I\'m 100% new to the Design Pattern stuff but as I see since a Singleton by definition won\'t

10条回答
  •  心在旅途
    2020-12-12 20:27

    I have used the second version (var singleton = {};) for everything from Firefox extensions to websites, and it works really well. One good idea is to not define things inside the curly brackets, but outside it using the name of the object, like so:

    var singleton = {};
    singleton.dothis = function(){
    
    };
    singleton.someVariable = 5;
    

提交回复
热议问题