most simple JS debounce

in #javascript8 years ago

#Snippets to use - most simple JS debounce

in the live of programming you may have performance issues here and ther due to x amount of executed functions when you'd just need them executed once .. when everything has renered or has been calculated.
Thus a debounce function comes in handy.
There's a lot complicated ones out which are nice but that you might not need all of the time.

The most simple I know of is this:

let timeout;

function myFunction(){
    clearTimeout(timeout);
    timeout = setTimeout(function(){
      myDebouncedFunction();
    }, 200);
}


simple as that. 
Enjoy if it gives you anything.