<input style="margin-top: 25px" onkeyup="debounced()" />
<p id='p'></p>
const p = document.querySelector('#p')

function debounce(func, delay = 1000) {
  let timeoutId;

  return function (...arguments) {
    p.innerHTML += "<br/>function called";
    clearTimeout(timeoutId);

    timeoutId = setTimeout(() => {
      func(...arguments);
    }, delay);
  };
}

function doSomething() {
  p.innerHTML += "<br/>I am doing something"
}

const debounced = debounce(doSomething);

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.