Is there a way to use setInterval
without relying on global variables? I am interested in wrapping all function variables used by setInterval inside a closure for better encapsulation, like this:
var wrap = function (f){
var local1, local2, ...;
return function () { return f(); }
}
I know the above method doesn't work as intended, but the concept is to pass wrap(f)
instead of f
to setInterval
, ensuring that the local variables of f
are contained within the wrapper and do not clutter the global scope.