Horje
debounce js Code Example
debounce js
function debounce(fn, delay) {
  let timer;
  return (() => {
    clearTimeout(timer);
    timer = setTimeout(() => fn(), delay);
  })();
  
};

// usage
function someFn() {
  console.log('Hi')
};

debounce(someFn, 1000);
debounce js
const debounce = (fn, delay) => {
  let timer;
  return function () {
    clearTimeout(timer);
    timer = setTimeout(fn, delay);
  };
};

// Example
let count = 0;
const increaseCount = (num) => {
  count += num;
  console.log(count);
};

window.addEventListener('scroll', debounce(increaseCount.bind(null, 5), 200));
debounce js
function debounce(func, timeout = 300){
  let timer;
  return function(...args) {
    if (timer) {
      clearTimeout(timer);
    }
    
    timer = setTimeout(() => {
      func.apply(this, args);
    }, timeout);
  };
}




Javascript

Related
convert to datetime in jquery Code Example convert to datetime in jquery Code Example
how to kill node port Code Example how to kill node port Code Example
how to right plain text format file in node js Code Example how to right plain text format file in node js Code Example
how to access child img src in jquery Code Example how to access child img src in jquery Code Example
regex only digits Code Example regex only digits Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
9