Promise 对象一章关于 finally 的实现的问题
bsc2xp opened this issue · comments
bsc2xp commented
文中对于 finally 的实现给出了示例:
Promise.prototype.finally = function (callback) {
let P = this.constructor;
return this.then(
value => P.resolve(callback()).then(() => value),
reason => P.resolve(callback()).then(() => { throw reason })
);
};
这里为什么要使用 P.resolve(callback())?写成下面不行吗?
return this.then(
value => {try {callback();} catch(err){}; return value},
reason => {try {callback();} catch(err){}; throw reason }
);
Ruan YiFeng commented
此处不答疑