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.

Coin Marketplace

STEEM 0.09
TRX 0.30
JST 0.034
BTC 112483.14
ETH 3985.86
USDT 1.00
SBD 0.59