const input = document.getElementById('input'); const debounc = (func, waitTime) => { let timer; return (...args) => { clearTimeout(timer); timer = setTimeout(() => { func(...args); }, waitTime); }; } function getData(e) { console.log(e.target.value) }; const debouncApi = debounc(getData, 1000); input.addEventListener('input', debouncApi);
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter