标签:err else The === 异步执行 this out pre cti
···js
function Promise(fn) {
let state = "pending";
let val = null // 异步执行的值(结果)
let deffer = [];
this.then = function(onFulfilled) {
if(state === "pending") {
deferreds.push(onFulfilled);
return this;
}
onFulfilled(value);
return this
}
function resolve(newValue) {
value = newValue;
state = "fulfilled";
// deferred(value);
// 保证deferred 有值
setTimeout(() => {
deffer.forEach((deferred) => {
deferred(value);
});
}, 0);
}
fn(resolve);
}
new Promise((resolve, reject)=> {
if (true){
resolve(3);
} else {
reject(error);
}
}).then((res)=> { console.log(res)})
···
标签:err else The === 异步执行 this out pre cti
原文地址:https://www.cnblogs.com/he-zhi/p/10156026.html