亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

If Promise object rejects itself - Stack Overflow
女神的閨蜜愛上我
女神的閨蜜愛上我 2017-06-14 10:53:56
0
2
822

Code:

            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);

Only reject is output under Firefox, input normally under Chrome, and then Uncaught (in promise) will appear

Excuse me, why does an uncaught exception occur? The catch of p is clearly defined, and why does Firefox only output reject and the operation of outputting p has no effect (in fact, it should be caused by an uncaught exception)


Supplement:
The reason for the uncaught exception is that although the second function is not defined in then, then is still run, and the cause and status are passed to the returned new Promise object. The Promise object does not have a catch callback, so an exception is reported
But the reason why the output p in Firefox has no effect is still unclear

女神的閨蜜愛上我
女神的閨蜜愛上我

reply all(2)
伊謝爾倫
var der = {};

var p = new Promise(function (resolve, reject) {
    der.reject = reject;
})
// 下面修改成這個樣子,因為then內部的處理函數(shù)也需要異常捕獲
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);
學霸

Promise is equivalent to a standard. Any prototype that conforms to the standard can be called a promise. Different browsers may have different features outside the standard. Obviously, Firefox believes that .catch and .then can be declared separately, and then at runtime Response, that is, no error is reported as you mentioned above; and Google believes that .catch should be handled together with the exception in .then, so it needs to be applied to the promise after .then. If you use .then().catch together, Google will not report an error. The underlying reason may be that one is based on events and the other is based on polling.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template