function Promise(fn) {
this.status = "pending"
this.value = ""
const that = this
try {
fn(resolve, reject)
} catch (e) {
reject(e)
}
function resolve(value) {
that.value = value;
that.status = "resloved"
}
function reject(value) {
that.value = value;
that.status = "rejected"
}
}
Promise.prototype.then = function (onReslved, onRejected) {
if (self.status === 'resolved') {
onReslved(this.value);
}
if (self.status === 'rejected') {
onRejected(this.reason);
}
}
转载请注明原文地址:https://blackberry.8miu.com/read-6747.html