Skip to content

Instantly share code, notes, and snippets.

@IUnknown68
Created June 2, 2017 06:09
Show Gist options
  • Save IUnknown68/114d21ad776a09ae3cd70081daeeb26b to your computer and use it in GitHub Desktop.
Save IUnknown68/114d21ad776a09ae3cd70081daeeb26b to your computer and use it in GitHub Desktop.
Combined debounce and throttle
function debounceAndThrottle(fn, timeout) {
var throttled = _.throttle(function() {
fn.apply(null, arguments);
}, timeout)
return _.debounce(function() {
throttled.apply(null, arguments);
}, timeout);
}
var fn = debounceAndThrottle((a, b) => {
console.info('RUNNING', a, b);
}, 5000);
$(document).ready(() => {
$('#btn').on('click', () => {
console.log(' click');
fn('a', 'c');
});
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment