(_=1)=>$=>_++
This function utilizes arrow syntax and is equivalent to:
function f(_ = 1) {
return $ => _++;
}
$ => _++;
is also an arrow function that captures the closure _
, increments it, and returns the value (postfix increment, so it returns the value first and then increments it):
function f(_ = 1) {
return function($) { return _++; };
}
Therefore, the code translates to:
function Counter(count = 1) {
return function() { return count++; };
}
(renamed _
to count
and removed redundant $
variable)
The Counter
function will return the previous value incremented by 1 each time, starting from the initial count
value, similar to a counter.