Taking a look at code from Leaflet api
My question is why wrapperFn.apply(context, args);</code> and <code>fn.apply(context, args);
using apply()
and not call()
.
How do you know which one to use ?
Confused because I don't know ahead of time if my passing function is using an array or not.
limitExecByInterval: function (fn, time, context) {
var lock, execOnUnlock;
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);
fn.apply(context, args);
};
},