Skip to content

Instantly share code, notes, and snippets.

@MrMeison
Last active March 21, 2020 17:45
Show Gist options
  • Select an option

  • Save MrMeison/39a1a4e68ff7e27afebaf5d1657677ef to your computer and use it in GitHub Desktop.

Select an option

Save MrMeison/39a1a4e68ff7e27afebaf5d1657677ef to your computer and use it in GitHub Desktop.
(function () {
window.debounce = function(callback, ms) {
var isCooldown = false;
return function() {
if (isCooldown) return;
callback.apply(this, arguments);
isCooldown = true;
setTimeout(function() {
isCooldown = false;
}, ms);
};
}
})();
// использование
var button = ...;
var onClick = function(evt) {
console.log('test', evt);
}
var deboucedOnClick = window.debounce(onClick, 500);
button.addEventListener('click', deboucedOnClick);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment