javascript 链式承诺电话
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript 链式承诺电话相关的知识,希望对你有一定的参考价值。
var asyncAdd = (a, b) => {
return new Promise((resolve, reject) => {
setTimeout(() => {
if (typeof a === "number" && typeof b === "number") {
resolve(a + b);
} else {
reject("Inputs must both br numbers");
}
}, 2000);
});
};
asyncAdd(12, 8)
.then(res => {
console.log("Result:", res);
return asyncAdd(res, 33);
})
.then(res => {
console.log("Result:", res);
return asyncAdd(res, 100);
})
.then(res => {
console.log("Final result: ", res);
})
.catch(errorMessage => {
console.log(errorMessage);
});
以上是关于javascript 链式承诺电话的主要内容,如果未能解决你的问题,请参考以下文章