bit*_*its 1 javascript promise
我想知道如何防止复制以下代码中的代码。我复制了这个函数wishModel.createWish()。复制代码的原因是:
感谢您帮助我改进我的代码!
if (copyExistsOnList) {
var copyWarningPopup = $uibModal.open({...});
copyWarningPopup.result.then(function (wish) {
wishModel.createWish(newWish, userID, userID, wish._id);
});
} else {
wishModel.createWish(newWish, userID, userID, wish._id);
}
Run Code Online (Sandbox Code Playgroud)
您可以为第二种情况做出立即解决的承诺,然后您总是有一个可以将最终的承诺链接then到:
(copyExistsOnList ? $uibModal.open({...}).result : Promise.resolve(wish))
.then(function (wish) {
wishModel.createWish(newWish, userID, userID, wish._id);
});
Run Code Online (Sandbox Code Playgroud)