I am fairly new to Javascript and I have picked up a codebase in which I see the following snippet:
if (DEBUG == false) { // WHAT S ALL THIS?!!
while ((request = UrlS.pop()) != null) {
(function() {
var counterDB = (function() {
var id = 0;
return function() {
return id++;
}; // Return and increment
})();
var tw = items[num];
console.log("Request " + request);
getFeed(request, tw, httpRequestCallback, counterDB);
})();
}
} else { // WHAT S ALL THIS?!! #2
(function() {
var counterDB = (function() {
var id = 0;
return function() {
return id++;
}; // Return and increment
})();
var tw = items[num];
request = UrlS.pop();
getFeed(request, tw, httpRequestCallback, counterDB);
})();
}
Especially around the counterDB
var, what is the point of creating so many nested anonymous functions?
with a quick search, i found that it is used elsewhere for a check: `
if(counterDB()<maximumSolutions)`
why all this? why not just CurrentModule.increment()
or smth?