JSFiddle - React, Tailwind, and code Playground
JavaScript
function makeCounter() {
var currentCount = 0;
return {
getNext: function() {
return ++currentCount;
},
set: function(value) {
currentCount = value;
},
reset: function() {
currentCount = 0;
}
};
}
var counter = makeCounter();
alert( counter.getNext() );