顺序和实际估计相差挺大
async function async1() { console.log('async1 start') await async2() console.log('async1 end') } async function async2() { console.log('async2') } console.log('script start') setTimeout(function () { console.log('setTimeout') }) async1() new Promise(function (resolve) { console.log('promise1') resolve() }).then(function () { console.log('promise2') }) console.log('script end') // 结果顺序 // hong // 微任务 // log // script start // async1 start // async2 // async1 end // promise1 // script end // promise2 // setTimeout
Promise.prototype.myAll = function (promises) { return new Promise((resolve, reject) => { let allRes = [] let num = 0 for (let p of promises) { p.then(res => { allRes.push(res) num++ if (num === promises.length) { resolve(allRes) } }).catch(err => { reject(err) }) } }) }
实习真没时间准备面试,感觉很多还是需要像八股一样突击的
#秋招##滴滴##提前批#