/**
 * 防抖函数
 * @param handler
 * @param delay
 * @returns
 */
export function debounce<T extends (...args: any[]) => any>(handler: T, delay: number) {
    let timer: NodeJS.Timeout | null = null;
    return function (this: ThisParameterType<T>, ...args: Parameters<T>) {
        if (timer) {
            clearTimeout(timer);
        }
        timer = setTimeout(() => {
            handler.apply(this, args);
        }, delay);
    };
}
