Thursday, 11 May 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

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...