我讀的Javascript模式 recently.And我不明白下面的代碼,當談到單例模式:Singleton模式在Javascript
function Universe(){
var instance;
Universe=function Universe(){
return instance;
};
Universe.prototype=this;
//the new Universe below,refers to which one?The original one,
//or the one:function(){return this;} ??
instance=new Universe();
instance.constructor=Universe;
instance.bang="Big";
return instance;
}
Universe.prototype.nothing=true;
var uni=new Universe();
Universe.prototype.everything=true;
var uni2=new Universe();
uni===uni2;//true
關於這個例子的具體問題是什麼? – Brad
這看起來不太複雜......我會用其他模式。 –
@FelixKling肯定我會用其他方式,如使用closures.I只是不明白的代碼,所以我問你們... – user1825777