fn(this._resolve.bind(this), this._reject.bind(this)
this.callbacks.foreach(callback => this._handle(callback))
this.callbacks.foreach(callback => this._handle(callback))
if( this.state === 'pending') {
this.callbacks.push(callback)
let cb = this.state === 'fullfilled' ? callback.onFulfilled : callback.onRejected
// 没定义 onFulfilled 或者 onRejected
cb = this.state === 'fullfilled' ? callback.resolve : callback.reject
then(onFulfilled = null, onRejected = null){
// 每次 then 都会创建新的 Promise 实例
return new Promise((resolve, reject) => {
this._handle(onFulfilled, onRejected, resolve, reject)
// onFulfill为null,仅在onReject里面被调用
return this.then(null, onError)