1 class NewPromise extends Promise{ 2 constructor(fn){ 3 4 const fn2 = function(resolve, reject) { 5 const reject2 = (err) => { 6 setTimeout(() => {reject(err);}, 0) 7 }; 8 9 try { 10 fn(resolve, reject2); 11 } catch (error) { 12 reject2(error) 13 } 14 } 15 16 17 super(fn2); 18 } 19 } 20 21 window.Promise = NewPromise;
异步异常捕获, 如果不重写,会抛好几个错误。 直接将这个代码设置为插件就OK