Let's say I have a table that contains names and I want to use all of that names in a function.
e.g var names = ['joe','sam', 'nick'];
Lets say I have the following function:
function doSomething (string1, NAME, string2, callback){
....
console.log(string1," ",NAME," ",string2);
...
callback(null,"ok");
}
Assuming it is asynchronous, I will be using the async.each function.
Moreover, I want to pass the variables in the function, using bind like this :
async.each(names,doSomething.bind(this, "example1", "example2",function(err){
console.log(err);
});
I get the following msgs :
example1 example2 joe
example1 example2 nick
example1 example2 sam
What I want is to bind the strings in the 1st and 3rd position and assign the name to the second. Can this be done? And how? Am I missing something in the fundamentals of JavaScript here?