LuckyWinty / fe-weekly-questions

A pro to record some interview questions every week...
MIT License
342 stars 34 forks source link

执行代码,求输出 #45

Open LuckyWinty opened 4 years ago

LuckyWinty commented 4 years ago
const promise = Promise.resolve()
  .then(() => {
    return promise
  })
promise.catch(console.error)
LuckyWinty commented 4 years ago

输出:[TypeError: Chaining cycle detected for promise #] 解释:promise.then 类似于 process.nextTick,都会将回调函数注册到 microtask 阶段。上面代码会导致死循环