promise问题
来源:8-20 手写 Promise-then 的链式调用
 
			慕仰5120631
2022-08-28
if (this.state === 'pending') {
            const p1 = new MyPromise((resolve, reject) => {
                this.resolveCallbacks.push(() => {
                    try {
                        const newValue = fn1(this.value)
                        resolve(newValue)
                    } catch (err) {
                        reject(err)
                    }
                })
                this.rejectCallbacks.push(() => {
                    try {
                        const newReason = fn2(this.reason)
                        reject(newReason)
                    } catch (err) {
                        reject(err)
                    }
                })
            })
            return p1
        }
当this.state === pending的时候,resolve(newValue)和reject(newReason)这两个函数不应该是在上一个promise中异步执行的吗,为什么产生的结果会添加到p1上呢
写回答
	1回答
- 
				  双越 2022-08-28 根据代码逻辑,resolve(newValue)和reject(newReason) 完全是 new Promise( .... ) 里面的内容,即 p1 的回调函数内容。 和上一个 promise 已经没关系了。 00
相似问题
