首页 > 其他 > 详细

单例模式 (3)

时间:2014-09-04 23:32:10      阅读:339      评论:0      收藏:0      [点我收藏+]
 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)

原文:http://www.cnblogs.com/lihaozhou/p/3956978.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!