var Singleton = (function(){
  var instance;

  function init() {
    var privateVariable = '123';
    function privateMethod() {
      console.log('i am a private method!');
    }
    return {
      publicMethod: function(){
         console.log('i am a public method!');
      },
      publicProperty: '456'
    }
  }
  return {
    getInstance: function(){
      if(!instance){
        instance = init();
      }
      return  instance;
    }
  }
})()

 

相关文章:

  • 2022-02-10
  • 2021-05-16
  • 2022-03-05
  • 2021-11-22
  • 2021-05-16
  • 2021-06-18
  • 2021-07-15
  • 2021-10-29
猜你喜欢
  • 2022-12-23
  • 2021-05-04
  • 2021-05-28
  • 2021-12-18
  • 2021-06-19
  • 2021-10-13
  • 2022-02-02
相关资源
相似解决方案