JSFiddle - React, Tailwind, and code Playground
by der_robert
JavaScript
function throttle(func, delay) {
let lastCall = 0;
return function (...args) {
const now = new Date().getTime();
console.log(now, lastCall, (now - lastCall), delay);
if (now - lastCall >= delay) {
console.log("sdfsdsfds");
func(...args);
lastCall = now;
}
};
}
function showmsg(){
console.log("MSG");
}
const throttledResizeHandler = throttle(showmsg, 20000);
window.addEventListener('resize', throttledResizeHandler);