1
Fork 0
href-plus/source/ts/utilities/debounce.ts

16 lines
284 B
TypeScript
Raw Normal View History

2022-01-03 17:21:21 +00:00
export default function debounce(
this: any,
fn: (...args: any[]) => any,
timeout = 250,
): typeof fn {
let timeoutId: number;
return (...args) => {
clearTimeout(timeoutId);
timeoutId = window.setTimeout(() => {
fn.apply(this, args);
}, timeout);
};
}