案例1
process.nextTick(() => {console.log('111');});
const promise = new Promise(resolve => {
console.log('222');
resolve();
});
setTimeout(() => {console.log('333');}, 100);
promise.then(() => {console.log('444');});
案例2
Promise.resolve().then(() => {console.log('111');});
process.nextTick(() => {
console.log('222');
})
setTimeout(() => {
console.log('333');
}, 0)
console.log('444');
案例3
console.log('111')
setTimeout(() => {
console.log('222')
}, 0)
new Promise((resolve) => {
console.log('333')
resolve()
})
.then(() => {
console.log('444')
})
.then(() => {
console.log('555')
})
console.log('666')
案例4
process.nextTick(() => {
console.log('111');
});
setTimeout(() => {
console.log('222');
}, 0);
const promise = Promise.resolve();
promise
.then(() => {
console.log('333');
process.nextTick(() => {
console.log('444');
});
setTimeout(() => {
console.log('555');
}, 0);
})
.catch(() => {
console.log('666');
})
.catch(() => {
console.log('777');
})