function Demo(name) { this.name = name;
}var getSingle = function(fn) { var result; return function() { console.log(arguments.length); return result || (result = fn.apply(this, arguments));
}
};const aa = new getSingle(Demo)('a');const bb = new getSingle(Demo)('b');console.log(aa === bb); //trueconsole.log(aa.name); // TypeError: aa is undefinedconsole.log(bb); // undefined為什么aa.name和bb未定義呢?
關(guān)于JS單例模式的一個問題
哆啦的時光機(jī)
2018-11-13 22:30:12