Skip to content

Latest commit

 

History

History
13 lines (10 loc) · 376 Bytes

File metadata and controls

13 lines (10 loc) · 376 Bytes
function debounce(func, ms) {
  let timeout;
  return function() {
    clearTimeout(timeout);
    timeout = setTimeout(() => func.apply(this, arguments), ms);
  };
}

Lệnh gọi debounce trả về một wrapper. Khi được gọi, nó lên lịch cuộc gọi hàm ban đầu sau ms đã cho và hủy bỏ thời gian chờ như vậy trước đó.