美文网首页
JS| arrayFunction

JS| arrayFunction

作者: 玫瑰的lover | 来源:发表于2024-10-28 00:07 被阅读0次

// 实现节流和防抖函数
export const debounce = (
fn: () => void,
delay: number
): ((...args: any[]) => void) => {
let timerId: number | undefined = undefined;
function wrapper(...args: any[]): void {
if (timerId) {
clearTimeout(timerId);
}
timerId = setTimeout(() => {
fn.apply(this, args as Array);
}, delay);
}
return wrapper;
};

相关文章

网友评论

      本文标题:JS| arrayFunction

      本文链接:https://www.haomeiwen.com/subject/fsyprjtx.html