Consider two examples below...
TEST 1
function test1() {
return new Promise(function () {
return 123;
});
}
test1()
.then(function (data) {
console.log("DATA:", data);
return 456;
})
.then(function (value) {
console.log("VALUE:", value);
});
It outputs nothing.
TEST 2
function test2() {
return new Promise(function (resolve, reject) {
resolve(123);
});
}
test2()
.then(function (data) {
console.log("DATA:", data);
return 456;
})
.then(function (value) {
console.log("VALUE:", value);
});
It outputs:
DATA: 123
VALUE: 456
What are the drawbacks or spec contradictions for a promise constructor not to simply resolve a returned value in TEST 1?
Why does it have to be a different result than in TEST 2?
I'm trying to understand how a constructed promise object is different from a then-able object as per the promise spec.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…