关于javascript:手动实现最简版promise

7次阅读

共计 293 个字符,预计需要花费 1 分钟才能阅读完成。

promise 特点剖析
1、promise 是一个类,其构造函数接管执行函数 executor,该函数接管两个参数也为函数,将第一个函数定义为 resolve,第二个函数定义为 reject
2、传入的函数中执行 resolve 示意胜利,执行 reject 示意失败,传入的值会传给 then 的回调函数
3、promise 返回 then 办法,该办法有两个参数,一个执行胜利的回调函数,一个是执行失败的回调函数,then 办法在 resolve 和 reject 执行之后(采纳公布订阅者模式),并且 then 办法中的值是作为 resolve 和 reject 的参数
4、promise 反对链式调用,then 返回 new promise

正文完
 0