Last active
March 21, 2020 17:45
-
-
Save MrMeison/39a1a4e68ff7e27afebaf5d1657677ef 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 () { | |
| 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