How it is work?
function(){...}();
I can't understand what's going on. I think this is javascript not node.js
puzzle. But I can not find solution.
fs.readdir(filesDir, function(err, files) {
if (err) throw err;
for (var index in files) {
**var task = (function(file) {**
return function() {
fs.readFile(file, function(err, text) {
if (err) throw err;
countWordsInText(text);
checkIfComplete();
});
}
**})(filesDir + '/' + files[index]);**
tasks.push(task);
}
for (var task in tasks) {
tasks[task]();