function debounce<TFn>(fn, initialOptions): (...args) => void
function debounce<TFn>(fn, initialOptions): (...args) => void
定义于:debouncer.ts:203
创建一个防抖函数,该函数将延迟调用提供的函数,直到经过指定的等待时间。 在等待期间的多次调用将取消先前待处理的调用并重置计时器。
这是从 Debouncer 类中提取的简单函数包装器实现。如果您需要对防抖行为进行更多控制,请直接使用 Debouncer 类。
如果 leading 选项为 true,则函数将在第一次调用时立即执行,然后在允许另一次执行之前等待延迟。
• TFn extends AnyFunction
TFn
DebouncerOptions<TFn>
Function
...Parameters<TFn>
void
const debounced = debounce(() => {
saveChanges();
}, { wait: 1000 });
// 重复调用,但每秒最多执行一次
inputElement.addEventListener('input', debounced);
const debounced = debounce(() => {
saveChanges();
}, { wait: 1000 });
// 重复调用,但每秒最多执行一次
inputElement.addEventListener('input', debounced);