Taking a look at code from Leaflet API
Getting lost with arguments and closures.
My second log output of arguments is an empty array. Shouldn't be the same at the first log.
limitExecByInterval: function (fn, time, context) {
var lock, execOnUnlock;
// Log output 1
console.log(arguments);//[foo(), 10000, Window a.html]
return function wrapperFn() {
var args = arguments;
if (lock) {
execOnUnlock = true;
return;
}
lock = true;
setTimeout(function () {
lock = false;
if (execOnUnlock) {
wrapperFn.apply(context, args);
execOnUnlock = false;
}
}, time);
//Log output 2
console.log(args) //[]
fn.apply(context, args);
};
},