Skip to content

Instantly share code, notes, and snippets.

@ashwinkumar2438
Last active October 14, 2020 09:26
Show Gist options
  • Save ashwinkumar2438/14cdf38f886344ed8177abc75d9d5369 to your computer and use it in GitHub Desktop.
Save ashwinkumar2438/14cdf38f886344ed8177abc75d9d5369 to your computer and use it in GitHub Desktop.
//takes function to be debounced and delay time to fire.
/*returns passed function wrapped with settimeout to delay fire
and updates to settimeout whenever called. */
let debounce=(fn,timedelay)=>{
let timerid=null;
return function(){
clearTimeout(timerid);
timerid=setTimeout(fn.bind(this,...arguments),timedelay);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment