每日一题答案

如题

Posted by hdj on August 2, 2022

##6. 代码输出结

   Promise.resolve(1)
   .then(2)
   .then(Promise.resolve(3))
   .then(console.log)

输出结果如下:

    1
    Promise {<fulfilled>: undefined}

可以拆解为

    // 源码上 参数1 onFufilled 不为 function则转为functuon
    // onFufilled 执行 state的结果1
    // onFufilled(1)
   Promise.resolve(1)
   .then(2)      // onFufilled(1)
   .then(Promise.resolve(3))       // onFufilled(1)    
   .then(console.log)   // console.log(1)=> console.log的返回值为undefined