return makeFirstPromise()
.then(function(res1) {
(...)
})
.then(function(res2) {
(...)
})
.then(function(res3) {
// **here I need to access res1**
});
我想知道当我需要访问前一个承诺时,是否有最佳做法导致我的承诺链的后续功能。关于JavaScript Promise的最佳做法
我看到了两个可能的解决方案:
var r1;
return makeFirstPromise()
.then(function(res1) {
r1 = res1;
(...)
})
.then(function(res2) {
(...)
})
.then(function(res3) {
console.log(r1);
});
或窝后的第一个承诺,但它在视觉上打破了链序列:
return makeFirstPromise()
.then(function(res1) {
(...)
return secondPromise(res2)
.then(function(res3) {
console.log(res1);
});
});
任何想法?
的[?如何访问的。那么()链先前承诺的结果(精确复制http://stackoverflow.com/questions/28250680/how-do-i -access-previous-promise-results-in-a-then-chain) – Bergi 2015-01-31 10:58:08