JS模式之单例模式基本用法
本文实例讲述了JS模式之单例模式基本用法。分享给大家供大家参考。具体如下:
//singleton
varSingletonTester=(function(){
functionSingleton(options){
options=options||{};
this.name="SingletonTester";
this.pointX=options.pointX||6;
this.pointY=options.pointY||10;
};
varinstance;
var_static={
name:"SingletonTester",
getInstance:function(options){
if(instance===undefined){
instance=newSingleton(options)
};
returninstance;
}
};
return_static;
})();
希望本文所述对大家的javascript程序设计有所帮助。