# throttle

function throttle(fn, wait) {
  var time;

  return function() {
    var context = this;
    var args = arguments;

    if (!time) {
      time = setTimeout(() => {
        time = null
        fn.call(context, args)
      }, wait);
    }
  };
}

function add() {
  console.log(666);
}

const a = throttle(add, 500);

setTimeout(a, 400);
setTimeout(a, 950);
setTimeout(a, 1250);
setTimeout(a, 1550);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
Last Updated: 6/27/2023, 7:40:45 PM