zoukankan      html  css  js  c++  java
  • 设计模式

    单例模式

    function Universe() {
      //缓存实例
      var instance = this;
    
      this.start_time = 0;
      this.bang = 'Big';
    
      //重写改构造函数
      Universe = function() {
        return instance;
      };
    }
    
    Universe.prototype.nothing = true;
    
    // 测试
    var uni = new Universe();
    var uni2 = new Universe();
    console.log(uni === uni2); // true
    
    console.log(uni.nothing) // true
    console.log(uni2.nothing) // true
    
    Universe.prototype.everything = true;
    
    console.log(uni.everything) // undefined
    console.log(uni2.everything) // undefined
    

      

  • 相关阅读:
    五一集训——图论
    Luogu P3942 将军令
    8.14 Round 1
    8.10 Round 1
    8.9 Round 1
    8.7 Round 2
    8.7 Round 1
    8.6 Round 1
    8.5 Round 2
    FHQ-Treap
  • 原文地址:https://www.cnblogs.com/daqianduan/p/4424277.html
Copyright © 2011-2022 走看看