首页 > 代码库 > javascript实现单例模式

javascript实现单例模式

var SingleTon = (function(){  var initinstance;  function myConstructor(){    return{      publicMethod : function(){        alert(this.value);      },      value : ‘haha‘    }  }  return{    getInstance : function(){      if(!initinstance){        initinstance =  myConstructor();      }      return initinstance;    }  }})()SingleTon.getInstance().publicMethod();