我已经将我的代码重组为承诺,并构建了一个由多个回调组成的精彩长扁平承诺链.then().最后我想返回一些复合值,并且需要访问多个中间承诺结果.但是,序列中间的分辨率值不在最后一个回调的范围内,我该如何访问它们?
function getExample() {
return promiseA(…).then(function(resultA) {
// Some processing
return promiseB(…);
}).then(function(resultB) {
// More processing
return // How do I gain access to resultA here?
});
}
Run Code Online (Sandbox Code Playgroud) 根据node-fetch文档node-fetch
我们可以得到这样的响应状态
fetch('https://github.com/')
.then(res => {
console.log(res.status);
});
Run Code Online (Sandbox Code Playgroud)
并获取数据
fetch('https://api.github.com/users/github')
.then(res => res.json())
.then(jsonData => console.log(jsonData));
Run Code Online (Sandbox Code Playgroud)
我有一个场景,我需要从响应中返回JSON数据和状态.我试着这样用
fetch('https://api.github.com/users/github')
.then(res => res.json())
.then(jsonData => {
console.log(jsonData);
console.log(jsonData.status);
});
Run Code Online (Sandbox Code Playgroud)
但是
执行console.log(jsonData.status)
不会返回状态.我如何获得状态和输出数据
javascript ×2
bluebird ×1
es6-promise ×1
fetch ×1
node-fetch ×1
node.js ×1
promise ×1
scope ×1