You can also use Function.prototype.bind to add an argument. bind will return a new function that, when called, calls the original function with the [index] files as the first argument.
But I do not know if this is a good way to do this.
var fs = require("fs"); var files = {"first.txt", "second.txt"}; for (var index in files) { fs.readFile(files[index], (function(filename, err, data) {
source share