# debounce

function debounce(fn, wait) {
  var time;

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

    clearTimeout(time);
    time = setTimeout(() => {
      time = null;
      fn.apply(context, args);
    }, wait);
  };
}

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

const a = debounce(add, 200);
a();
a();
setTimeout(add, 1000);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
Last Updated: 6/27/2023, 7:40:45 PM