我总是找不到这个问题的答案。如何使用Caolan的async.js节点模块将参数传递给async.each的迭代器函数?我想重用迭代器,但根据上下文需要使用不同的前缀保存内容。我的代码如下:
async.each(myArray, urlToS3, function(err){
if(err) {
console.log('async each failed for myArray');
} else {
nextFunction(err, function(){
console.log('successfully saved myArray');
res.send(200);
});
}
});
function urlToS3(url2fetch, cb){
//get the file and save it to s3
}
我希望你能够帮我实现以下功能:
async.each(myArray, urlToS3("image"), function(err){
if(err) {
console.log('async each failed for myArray');
} else {
nextFunction(err, function(){
console.log('successfully saved myArray');
res.send(200);
});
}
});
function urlToS3(url2fetch, fileType, cb){
if (fileType === "image") {
//get the file and save it to s3 with _image prefix
}
}
我找到了一个类似的关于coffeescript的问题,但是答案不起作用。如果我正在尝试做一些不符合惯用法的事情,我可以进行重构,但这似乎是一件非常合乎逻辑的事情。