I'm interested in this simple closure code from the article:
function getGetNext() {
let i = 2;
return function getNext() {
const next = i;
i = i * 2;
return next;
}
}
As a lisp coder [and not a JS coder], I'm wondering: why does the function getNext() have to be named? Why not just say something like: function getGetNext() {
let i = 2;
return function() {
const next = i;
i = i * 2;
return next;
}
}