//resolve和reject
function Promise(fn) {
this.status = 'pending'
this.value = ''
const _this = this
try {
fn(resolve, reject)
} catch (e) {
reject(e)
}
function resolve(value) {
_this.value = value
_this.status = 'resloved'
}
function reject(value) {
_this.value = value
_this.status = 'rejected'
}
}
//then方法实现
Promise.prototype.then = function (onReslved, onRejected) {
if (this.status === 'resolved') {
onReslved(this.value)
}
if (self.status === 'rejected') {
onRejected(this.reason);
}
}