Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

throttling function in javascript

function throttle(someFn, delay) {
  let flag = true;
  return (() => {
    if(flag){
      someFn();
      flag=false;
    }
    setTimeout(() => {flag=true;}, delay);
  })();
  
};

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

throttle(someFn, 1000);
 
PREVIOUS NEXT
Tagged: #throttling #function #javascript
ADD COMMENT
Topic
Name
8+8 =