Throttle Polyfill

Throttle will also cancel frequent events, But it will get executed once delay is completed in a repeat manner.

delay => New Function Call

Normal Click: 0

Throttled Click: 0

function Throttle(fn, delay) {
  let last = 0;

  return (...args) => {
    let newTime = new Date().getTime();
    if (newTime - last < delay) return;
    last = newTime;
    fn.apply(this, args);
  };
}