直接上代码:
var p = Promise.resolve({ then: x => { console.log('ok') } }) p.then(x=> { console.log('为什么这里不继续执行了?') })
var p = Promise.resolve() .then(x=> { console.log('ok') }) .then(x=> { console.log('这样就能') }) var p = new Promise(resolve => { resolve() }) .then(x=> { console.log('ok') }) .then(x=> { console.log('这样也能') })
var p = Promise.resolve({ // 这个是一个 thenable 对象, then: x => { // 这里 then 接受两个参数 resolve, 和 reject,有点像传进 new Promise 里的函数的参数,也就是说这里需要手动调用 resolve 或者 reject,p 的 then 里的函数才会被调用 console.log('ok'); x(); // 也就是说这里需要调用下 x 函数 } })
@zbinlin 理解了,非常感谢!
CNode 社区为国内最专业的 Node.js 开源技术社区,致力于 Node.js 的技术研究。
@zbinlin 理解了,非常感谢!