代码: var der = {}; var p = new Promise(function (resolve, reject) { der.reject = reject; }) p.then((v) => { console.log('resolve'); console.log(v); }) p.catch(function (v) { console.log(v); console.log('reject'); console.log(v); }); der.reject(p); console.log(p);火狐下只输出reject,chrome下正常输入,然后会出现Uncaught (in promise)请问,为什么会出现未捕获的异常呢,p的catch明明定义了,而且为什么火狐下只输出reject,输出p的操作都无效果(实则应该也是出现异常未捕获导致)
1 回答
陪伴而非守候
TA贡献1757条经验 获得超8个赞
var der = {};
var p = new Promise(function (resolve, reject) {
der.reject = reject;
})
// 下面修改成这个样子,因为then内部的处理函数也需要异常捕获
p.then((v) => {
console.log('resolve');
console.log(v);
}).catch(function (v) {
console.log(v);
console.log('reject');
console.log(v);
});
der.reject(p);
console.log(p);
添加回答
举报
0/150
提交
取消