我从dofactory.com复制了以下设计模式。我的问题是如何将其转换为async/await?
var Singleton = (function () {
var instance;
function createInstance() {
var object = new Object("I am the instance");
return object;
}
return {
getInstance: function () {
if (!instance) {
instance = createInstance();
}
return instance;
}
};
})();
function run() {
var instance1 = Singleton.getInstance();
var instance2 = Singleton.getInstance();
console.log("Same instance? " + (instance1 === instance2));
}
1条答案
按热度按时间qgelzfjb1#
它可能是这样的(如果没有异步创建示例的代码,很难判断):