I'm using node async, and I'd like to pass a variable to the method that it uses within the second parameter... e.g:
async.map(submissions, addScore, function(err, submissions) {
if (submissions) {
return submissions;
}
});
I want to pass userId along with addScore but am not sure how to do this.
addScore is my method that I call on every submission and it requires a userId.
You can use a closure to put the userId into the addScore function scope:
var createAddScore = function(userId){
return function(val){
// do something with userID and val
}
}
then:
async.map(submissions, createAddScore(1), function(err, submissions) {
if (submissions) {
return submissions;
}
});