I am learning nodejs, coming from other languages (C#, etc) and some of the syntax has be confused.
For example this piece of code (I am sure it is fairly simple but would appreciate an explanation or at least a link to documentation that explains it)
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?