单例模式 (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);

 

posted @ 2014-09-04 22:14  菠萝君  阅读(114)  评论(0编辑  收藏  举报