Created
June 2, 2017 06:09
-
-
Save IUnknown68/114d21ad776a09ae3cd70081daeeb26b to your computer and use it in GitHub Desktop.
Combined debounce and throttle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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