Promise行为记录 - catch和then都被运行触发
#js,#javascript,#es6,#promise
今天封装http。运行结果和预期不一样。
经过和我老大华哥请教,和我后面在chrome100.0.4896.75的测试。记录本文。
1、promise 的 catch 和 then 的顺序会影响结果
new Promise((_resolve, rejects) => {
setTimeout(() => {
rejects();
}, 100);
})
.catch(() => {
console.log('1');
})
.then(() => {
console.log('2');
})

2、promise 的 then 后面 跟 then 可以 运行后面的then,但catch后面跟catch 不能运行后面的那个catch
new Promise((_resolve, rejects) => {
setTimeout(() => {
rejects();
}, 100);
})
.catch(() => {
return console.log('1');
})
.then(() => {
console.log('2');
})
.catch(() => {
console.log('3');
});

/**
* in the end
* 我们正改变着我们的世界..
*/

浙公网安备 33010602011771号