Can someone explain me how is the _.before function implemented as i dont really understand why the internal times
variable keeps track of every function call. Shouldn't it be in local scope and reset every time like normal functions ?
Code for _.before function :
// Returns a function that will only be executed up to (but not including) the Nth call.
_.before = function(times, func) {
var memo;
return function() {
if (--times > 0) {
memo = func.apply(this, arguments);
}
if (times <= 1) func = null;
return memo;
};
};
Thank you.