setTimeout(() => { console.log(1) }); const a = new Promise((resolve,reject)=>{ console.log(2); resolve(3) }) setTimeout(() => { console.log(4) }); const b = new Promise((resolve,reject)=>{ console.log(5) resolve(6) }) b.then(value=>console.log(value)) a.then(value=>console.log(value))
结果
2 5 6 3 1 4
总结:
1、promise和process.nextTick在程序中是先于settimtout执行的;
2、在promise和process.nextTick里面的console语句的执行速度是三个中最快,它与promise和process.nextTick执行的顺序无关,只与promise和process.nextTick声明的顺序有关;