问题背景
由于项目中使用了Promise.allSettled
的语法,在chrome60浏览器中报错,错误为Promise.allSettled is not a function
问题解决
写了一个polyfill
兼容Promise.allSettled
的语法。
(function(){
const rejectHandler = reason => ({ status: 'rejected', reason });
const resolveHandler = value => ({ status: 'fulfilled', value });
Promise.allSettled = function (promises) {
const convertedPromises = promises.map(p => Promise.resolve(p).then(resolveHandler, rejectHandler));
return Promise.all(convertedPromises);
};
})
网友评论