2020-12-24 16:45:42 +02:00

15 lines
339 B
TypeScript

export const throttle = (func: Function, limit: number): Function => {
let inThrottle: boolean;
return function (this: any): any {
const args = arguments;
const context = this;
if (!inThrottle) {
inThrottle = true;
func.apply(context, args);
setTimeout(() => (inThrottle = false), limit);
}
};
};