📜  单例函数 javascript 代码示例

📅  最后修改于: 2022-03-11 15:01:09.761000             🧑  作者: Mango

代码示例2
var SingletonFactory = (function(){
    function SingletonClass() {
        //do stuff
    }
    var instance;
    return {
        getInstance: function(){
            if (instance == null) {
                instance = new SingletonClass();
                // Hide the constructor so the returned object can't be new'd...
                instance.constructor = null;
            }
            return instance;
        }
   };
})();