The code below is for a function that can only be invoked 3 times, the code is correct. What I don't understand quite well is this part:
var combi = returnIt() + returnIt() + returnIt();
I understand whats happening insight the threet function (and that func is being called up to counter==3) but how does it gets REMEMBERED outside of it? Not sure if I explained clear enough what I mean..
var returnIt = threet(function() {
return 5;
});
function threet(func){
var counter = 0;
return function(){
if(counter < 3){
counter++;
return func();
}
}
}
var combi = returnIt() + returnIt() + returnIt();
combi;