I am looking at the Leaflet api.
Is there a reason why in setTimeout, it is calling wrapperFn.apply(context, args); and not fn.apply(context, args); ?
I tried it out, and it gives me the same output. But wondering if there a significance to it ?
function a(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);
};
},
wrapperFnensures thatfnis not called repeatedly. You would lose this protection by usingfn. - joews