ts 版节流函数
// 节流函数
/* eslint-disable prefer-rest-params */
export function throttle(func, wait) {
let timeout: NodeJS.Timeout | null = null;
// eslint-disable-next-line func-names
return function (this: unknown, ...args) {
// eslint-disable-next-line @typescript-eslint/no-this-alias
const context = this;
// const args = arguments;
if (!timeout) {
timeout = setTimeout(() => {
timeout = null;
func.apply(context, args);
}, wait);
}
};
}

浙公网安备 33010602011771号