class Promise {
constructor (handelFunc) {
this.status = 'pedding'
this.vallue = ''
this.fulFilledList = []
this.rejectList = []
console.log(1)
handelFunc(this.triggeResolve.bind(this), this.triggeReject.bind(this))
}
then (onFulFilled, onReject) {
console.log(3)
const {value, status} = this
return new Promise((onNextFulFilled, onNextReject) => {
console.log(5)
switch(status) {
case 'pedding':
this.fulFilledList.push(onFulFilled)
this.rejectList.push(onReject)
break;
}
})
}
catch () {
}
triggeFulFilled () {
this.fulFilledList.forEach(item => item())
this.fulFilledList = []
}
triggeResolve (val) {
console.log(2)
setTimeout(() => {
console.log(4)
if (this.status != 'pedding') return
if (val instanceof Promise) {
val.then(
value => {},
err => {}
)
} else {
this.status = 'fulFilled'
this.value = val
this.triggeFulFilled()
}
}, 0)
}
triggeReject () {
}
static resolve () {
}
static reject () {
}
static all () {
}
static reace () {
}
}
let promise = new Promise((resolve, reject) => {
resolve('1234')
})
promise.then((val) => {
console.log(val)
})
console