Skip to content

Instantly share code, notes, and snippets.

@MatheusMK3 MatheusMK3/fn.debounce.js
Last active Jul 31, 2019

What would you like to do?
Função para debounce de eventos em Javascript
function debounce (fn, time) {
// Estado do throttle
let throttling = false
// Retorna uma função especial para fazer o debounce
return () => {
// Se estiver com throttle ativo, retornar
if (throttling) return;
// Ativa o throttle
throttling = true;
// Após um certo período, termina o throttle
setTimeout(() => { throttling = false }, time)
// Executa e retorna o resultado da função original
return fn.apply(arguments)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.