当我调用这个 promise 时,输出与函数调用的顺序不匹配。The.then出现在 之前.catch,即使 promise with.then被调用之后。这是什么原因?
const verifier = (a, b) =>
new Promise((resolve, reject) => (a > b ? resolve(true) : reject(false)));
verifier(3, 4)
.then((response) => console.log("response: ", response))
.catch((error) => console.log("error: ", error));
verifier(5, 4)
.then((response) => console.log("response: ", response))
.catch((error) => console.log("error: ", error));
输出
node promises.js
response: true
error: false
扬帆大鱼
哆啦的时光机
相关分类