I am learning NodeJS, coming from other languages (C#, etc) and I find some of the syntax to be confusing.
For example this piece of code:
for(var index in files) {
console.log("-->"+index);
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);
}
What is this? var task= (function(file){return function(){......}})(filesDir+.....);
There is a function that is calling a function and suddenly some parameters outside?
I am guessing it is defining a list of functions but what is the rule for this syntax?