day201-简单实现Promise(3)

要点

  1. promise的then方法框架

代码

/** promise-then方法 */
MyPromise.prototype.then = function (onFulfilled, onRejected) {
var self = this
// 标准2.2.1.1. If onFulfilled is not a function, it must be ignored.
onFulfilled = typeof onFulfilled === 'function' ? onFulfilled : function(v) { return v }
onRejected = typeof onRejected === 'function' ? onRejected : function(r) { return r }

// Promise对象存在以下三种状态,对三种状态采用不同处理
if (self.status === 'resolved') {
return new MyPromise(function(resolve, reject) {
// todo
})
}

if (self.status === 'rejected') {
return new MyPromise(function(resolve, reject) {
// todo
})
}

if (self.status === 'pending') {
return new MyPromise(function(resolve, reject) {
// todo
})
}
}
文章作者: lmislm
文章链接: http://lmislm.com/2019/08/02/2019-08-02/
版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 LMISLMのBlog