Debounce Function in JavaScript

A utility function that limits how often a function can fire, useful for search input or resize events.

An Nguyễn VănAn Nguyễn Văn
November 10, 2025
48 lượt xem
0 lượt lưu

Mã nguồn

1function debounce(fn, delay = 300) {
2  let timeout;
3  return (...args) => {
4    clearTimeout(timeout);
5    timeout = setTimeout(() => fn(...args), delay);
6  };
7}
8

Về tác giả

An Nguyễn Văn

An Nguyễn Văn

@an-nguyen-99

Test tiểu sử 3

Xem hồ sơ