JS模式-基本的单例模式

//singleton
var SingletonTester = (function(){
    function Singleton(options){
        options = options || {};
        this.name = "SingletonTester";
        this.pointX = options.pointX || 6;
        this.pointY = options.pointY || 10;
    };
    
    var instance;
    var _static = {
        name : "SingletonTester",
        getInstance : function(options){
            if(instance === undefined){
                instance = new Singleton(options)
            };
            return instance;
        }
    };
    return _static;
})();

 

posted @ 2013-11-17 23:44  方方和圆圆  阅读(401)  评论(0编辑  收藏  举报

再过一百年, 我会在哪里?