Tuesday, 15 August 2017

javascript - What's the difference between returning value or Promise.resolve from then()

What is the difference between:





new Promise(function(res, rej) {
res("aaa");

})
.then(function(result) {
return "bbb";
})
.then(function(result) {
console.log(result);
});






and this:





new Promise(function(res, rej) {
res("aaa");
})
.then(function(result) {
return Promise.resolve("bbb");

})
.then(function(result) {
console.log(result);
});





I'm asking as I'm getting different behaviour Using Angular and $http service with chaining .then(). A bit too much code hence first the example above.

No comments:

Post a Comment

casting - Why wasn't Tobey Maguire in The Amazing Spider-Man? - Movies & TV

In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...