Created
October 2, 2018 12:48
-
-
Save dondevi/466a3fabeb878de7ee7344c4fbaf900d to your computer and use it in GitHub Desktop.
This file contains hidden or 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 debounce (fn, delay) { | |
var timer = -1; | |
return function () { | |
var that = this; | |
var args = arguments; | |
window.clearTimeout(timer); | |
timer = window.setTimeout(function () { | |
fn.apply(that, args); | |
}, delay || 300); | |
}; | |
} |
This file contains hidden or 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 throttle (fn, delay) { | |
var on = true; | |
return function () { | |
if (!on) { return; } | |
on = false; | |
var that = this; | |
var args = arguments; | |
window.setTimeout(function () { | |
fn.apply(that, args); | |
on = true; | |
}, delay || 300); | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment