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);
1.4m articles
1.4m replys
5 comments
57.0k users