Skip to content

Instantly share code, notes, and snippets.

@ilhamgusti
Created February 19, 2020 02:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ilhamgusti/f4f276b6dbffb5f7fdadb8353f6ff30c to your computer and use it in GitHub Desktop.
Save ilhamgusti/f4f276b6dbffb5f7fdadb8353f6ff30c to your computer and use it in GitHub Desktop.
menunda event berjalan. menjalankan event ketika sekian detik aksi
function debounced(delay, fn) {
let timerId;
return function (...args) {
if (timerId) {
clearTimeout(timerId);
}
timerId = setTimeout(() => {
fn(...args);
timerId = null;
}, delay);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment