15 lines
339 B
TypeScript
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);
|
|
}
|
|
};
|
|
};
|