javascript - jQuery - delaying all functions calls declared with .on -
i using .on() function in jquery assign functions events.
var someevent = geteventname(someparams); // gets event, 'click' var somefunctionreference = getfunctionnamebasedonparams(someparams); // gets function reference $('.myelement').on(someevent, somefunctionreference); what wrap 'somefunctionreference' inside timeout or delay firing (by time; lets 250ms) without having go , modify every single function returned method.
is there way this?
i'll assume can't modify code in getfunctionnamebasedonparams, need create function returns function wrapped in timer.
function delayfunc(fn, ms) { return function() { var args = arguments; settimeout(function() { fn.apply(this, args); }, isnan(ms) ? 100 : ms); } } then pass function it.
var somefunctionreference = delayfunc(getfunctionnamebasedonparams(someparams), 250); be aware handler's return value meaningless, if return false, it'll have no effect.
Comments
Post a Comment