在以下代码中:
var p1 = new Promise(function (resolve, reject) {
throw 'test1';
});
var p2 = new Promise(function (resolve, reject) {
reject('test2');
});
p1.catch(function (err) {
console.log(err); // test1
});
p2.catch(function (err) {
console.log(err); // test2
});
Run Code Online (Sandbox Code Playgroud)
从api 使用reject(in p2)Promise和使用错误(in p1)之间有什么区别throw吗?
它完全一样吗?
如果它相同,为什么我们需要reject回调呢?