frontend-challenges icon indicating copy to clipboard operation
frontend-challenges copied to clipboard

6 - Debounce

Open marks0351 opened this issue 1 year ago • 0 comments

index.js

export function debounce(func, delay) {
  var canInvoke = true;
  var callbackFn;
  // your answer here
  return (args)=>{
    callbackFn = func.bind(this, args);
    if(canInvoke){
          canInvoke = false
          setTimeout(()=>{
              callbackFn()
              canInvoke = true;
          }, delay)
    }
  }
}

marks0351 avatar Feb 29 '24 13:02 marks0351