var singleton = (function(){ var instance; return function () { if (instance) return instance; instance = this; return instance; } }()); var obj = new singleton(); var obj2 = new singleton(); console.log(obj2 === obj); // true
时间: 2024-10-09 11:23:03