JSFiddle - React, Tailwind, and code Playground
JavaScript
function SomeFunc(func) {
var numba = 0;
var innerFunc = function() {
numba = func(numba);
return numba;
};
return innerFunc;
}
//this variable should persist the numba variable through closure. Incrementing each call by 1.
var closure = SomeFunc(function(numba) {
numba = numba + 1;
return numba;
});
document.writeln(typeof closure);
//document.writeln(closure.toSource());
document.writeln(closure());
document.writeln(closure());
document.writeln(closure());