// 手写promise构造器
class MyPromise{
#state = "pending"
#result = null
#changeState(state,data){
if(this.#state !== 'pending') return
this.#state = state
this.#result = data
}
constructor(executor){
const resolve = (data)=>{
this.#changeState('fufilled',data)
console.log('fufilled',data)
}
const reject = (data)=>{
this.#changeState('reject',data)
console.log('reject',data)
}
try{
executor(resolve,reject)
}catch(err){
reject(err)
}
}
}
const p = new MyPromise((resolve,reject)=>{
// resolve(1)
reject(2)
// throw 3
})