問題背景
由于項(xiàng)目中使用了Promise.allSettled
的語法帅刊,在chrome60瀏覽器中報(bào)錯淤堵,錯誤為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);
};
})