单体模式---静态属性中的实例

 1 function Universe() {
 2         //缓存实例
 3         var instance = this;
 4 
 5         this.start_time = 0;
 6         this.bang = "Big";
 7 
 8         Universe = function(){
 9             return instance;
10         };
11     }
12 
13     //var uni = new Universe();
14     //var uni2 = new Universe();
15     //console.log(uni === uni2);
16 
17 
18     Universe.prototype.nothing = true;
19 
20     var uni = new Universe();     //执行了一次 之后  Universe = function(){    return instance;};  断开了 prototype //Universe.prototype.nothing = true;
21 
22     Universe.prototype.everything = true;
23     
24     var uni2 = new Universe();
25 
26     console.log(uni.nothing);
27     console.log(uni2.nothing);
28 
29     console.log(uni.everything);
30     console.log(uni2.everything);
31 
32     console.log(uni.constructor.name);
33     console.log(uni.constructor === Universe);
疯癫不成狂,有酒勿可尝;世间良辰美,终成水墨白。
原文地址:https://www.cnblogs.com/chuyu/p/3296955.html