passing dynamic values in callback method
- by swastican
is there a way to pass dynamic values to callback function in js or jquery or nodejs.
for(var i = 0; i < 10; i++)
{
filename = 'file'+i+'.html';
request(url, function(error, response, body) {
test(error, response, body, filename);
});
function test(error, response, body, filename) {
console.log('file name ' + filename);
if(response.statusCode == 200){
console.log('done');
}
}
I refered this so article for passing values to callback function.
link: [JavaScript: Passing parameters to a callback function
the output always seems to be 9
How can i pass values dynamically? The callback function always refers the last value of filename.