js设计模式3 单粒

var Singleton = (function(){
  	function instance(options){
  		options = options || {};
  		this.name = "mySingleton";
  		this.pointX = options.pointX || 1;
  		this.pointY = options.pointY || 1;
  	}	
  	var myInstance;
  	return{
  		"getInstance":
  			function getInstance(options){
  				if(typeof(myInstance)=="undefined"){
  					myInstance = new	instance(options);
  				}
  				return myInstance;
  			}
  	}
  })();
  
  var hehe = Singleton.getInstance({"pointX":2,"pointY":3});
  alert(hehe.pointX+" "+hehe.pointY);

你可能感兴趣的:(js设计模式3 单粒)