手写Promise
手写Promise 构造函数
// 声明构造函数
function Promise(executor) {
this.PromiseState = "pending";
this.promiseResult = null;
// 保存回调函数
this.callbacks = [];
// 保存实例对象的this的值(也可以用匿名箭头函数)
let self = this;
// resolve函数
function res(data) {
// 设置状态...
zmblog.hashnode.dev4 min read