<分区>
如何将最终结果/回调返回给调用函数? 文档中的所有示例仅显示 console.log() 选项。
以下代码仅供示例。
function foo(input) {
async.parallel([
function(callback) {
callback(null, input.one);
},
function(callback) {
callback(null, input.two);
}
],
function(err, results) {
// What to do here? all examples include console.log()
// I want to return the result ([1, 2]) to the calling function!
});
}
var data = {"one": 1, "two": 2};
var bar = foo(data);
console.log(bar); // Will return [1, 2]
编辑:这个问题被标记为重复。另一篇文章没有解释这是如何对 javascript 和回调经验有限的人完成的。