Skip to content

Instantly share code, notes, and snippets.

Created March 1, 2019 16:53
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save iansvo/4dedfb28f97595faed110fd05c6632e1 to your computer and use it in GitHub Desktop.
// Inspired by @desandro's debounce.js
// Inspired by @ChrisFerdinandi's article:
function debounce( fn ) {
var timeout;
return function debounced() {
var _this = this,
args = arguments;
// If there's a timer, cancel it
if (timeout) {
// Setup the new requestAnimationFrame()
timeout = window.requestAnimationFrame(function () {
fn.apply( _this, args );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment