0
我想用Javascript使用承諾API做一些提取,然後使用我剛剛提取的所有值。喜歡的東西...鏈承諾和使用所有變量
// Use an Id to find thing 1, use thing 1 Id to find thing2, use thing 2 id to find thing 3,
// then use all of them.
thing1model.findById(thing1id).then(function(thing1) {
return thing2model.findById(thing1.id);
}).then(function(thing2) {
return thing3model.findById(thing2.id);
}).then(function(thing3) {
// Here I want to use all of thing1, thing2, thing3...
someFunction(thing1, thing2, thing3);
}).catch(function(err) {
console.log(err);
});
問題是thing1
和thing2
走出去的範圍在函數調用之後。我如何在最後的then
函數中使用它們?