return makeFirstPromise()
.then(function(res1) {
(...)
})
.then(function(res2) {
(...)
})
.then(function(res3) {
// **here I need to access res1**
});
Is there a recommended approach for accessing a previous promise result in a subsequent function of the promise chain?
I have identified two potential solutions:
var r1;
return makeFirstPromise()
.then(function(res1) {
r1 = res1;
(...)
})
.then(function(res2) {
(...)
})
.then(function(res3) {
console.log(r1);
});
Alternatively, nesting the promises after the first one, but this method disrupts the visual flow of the chain:
return makeFirstPromise()
.then(function(res1) {
(...)
return secondPromise(res2)
.then(function(res3) {
console.log(res1);
});
});
Any thoughts or suggestions on this matter?