解决办法
判断是否存在finally方法,不存在则在Promise原型上添加finally方法
if (!Promise.prototype.finally) { Promise.prototype.finally = function(callback) { this.then(res => { callback && callback(res) }, error => { callback && callback(error) }) } }
|
Promise 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 }) ); };
|