debouncedFn = $.debounce( fn , timeout , [ invokeAsap ], [ context ]);
true
/ false
, the default is false
. Parameter indicating which of the above debouncing
options debouncing
be used (the first is used by default)keyup
wasteful and unnecessary. You can decorate the handler so that it works only after the user stops pressing keys, say, for 300 milliseconds:
function onKeyUp() { ... };
$( 'input[name=suggest]' ).keyup($.debounce(onKeyUp, 300));
* This source code was highlighted with Source Code Highlighter .
$( 'input' ).bind( 'keyup blur' , $.debounce(process, 300));
* This source code was highlighted with Source Code Highlighter .
throttledFn = $.throttle( fn , period , [ context ]);
resize
window (or, say, on the mousemove
), you have some kind of heavy handler. You can “slow down” it:
$(window).resize($.throttle(doComplexomputation, 300));
As a result, the function will be executed no more than once every 300 milliseconds.
debounce
and throttle
, calling the first the second. Ajaxian also raised this topic .Source: https://habr.com/ru/post/60957/