I have a function:
setInterval(function () { var counter = 0; (function() { counter = counter + 1; console.log(counter); })(counter) }, 1000)
You could use a function which returns a function as closure over counter.
setInterval(function(counter) { return function() { console.log(++counter); }; }(0), 1000);
2.1m questions
2.1m answers
60 comments
57.0k users