var obj = {};
var Singleton = function(){
if(!obj) {
var obj = {};
}
return obj;
}
var o = new Singleton();
var o1 = new Singleton();
o.prop = 's';
console.log(o === o1); //false
console.log(o1.prop); //undefined
o
и o1
) разные, внутри каждого свой obj
.function Singleton () {
if (Singleton._instance) return Singleton._instance;
Singleton._instance = this;
};
var o = new Singleton();
var o1 = new Singleton();
console.log(o === o1); // true
o.prop = 's';
console.log(o1.prop); // s