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

16 lines
284 B
TypeScript

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);
};
}