promise 练习
宏队列(dom事件,ajax,定时器)和微队列(promise);微队列先于宏队列执行。
setTimeout(() => { console.log(1); }, 0); new Promise(resolve => { console.log(2); resolve() //resolve()函数执行了才会触发then里面的回调函数,不执行resolve()then回调函数不会执行的 }).then(() => { console.log(3); }).then(() => { console.log(4) }) console.log(5);
const first = () => new Promise((resolve, reject) => { console.log(3); const p = new Promise((resolve, reject) => { console.log(7); setTimeout(() => { console.log(5); resolve(6) //p的状态已经是fulfilled,不会再执行resolve()函数 }, 0); resolve(1) }) resolve(2) p.then(console.log) //then()是同步执行,把then()里面方法放入微队列中 }) first().then(console.log) console.log(4);
相关推荐
nmgxzm00 2020-11-10
xixixi 2020-11-11
88254251 2020-11-01
MarukoMa 2020-09-02
88234852 2020-09-15
陈旭阳 2020-08-31
whynotgonow 2020-08-19
前端开发Kingcean 2020-07-30
whynotgonow 2020-07-29
bowean 2020-07-08
前端开发Kingcean 2020-07-08
88520191 2020-07-05
88481456 2020-06-18
whynotgonow 2020-06-16
88520191 2020-06-13
88520191 2020-06-13
89500297 2020-06-13
前端开发Kingcean 2020-06-11