首页 > 代码库 > 单例模式 (3)

单例模式 (3)

 var SingletonTester = (function(){        function singleton(options){            options = options || {};            this.name = ‘Jackey‘;            this.age = options.age || 24;        }        var instance;        var _static = {            name:‘Jackey‘,            getInstance:function(options){                if(!instance){                    instance = new singleton(options);                }                return instance;            }        };        return _static;    })();    var test = SingletonTester.getInstance({age : 20})    console.log(test.age);

 

单例模式 (3)