Closed bsc2xp closed 1 year ago
文中对于 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 } );
此处不答疑
文中对于 finally 的实现给出了示例:
这里为什么要使用 P.resolve(callback())?写成下面不行吗?