UNPKG
@amxdev/throttle
Version:
latest (1.0.0)
1.0.0
Throttle a function to limit calls within a time frame.
@amxdev/throttle
/
dist
/
index.js
14 lines
(13 loc)
•
348 B
JavaScript
View Raw
1
2
3
4
5
6
7
8
9
10
11
12
13
14
"use strict"
;
Object
.
defineProperty
(
exports
,
"__esModule"
, {
value
:
true
});
exports
.
throttle
= throttle;
function
throttle
(
func, limit
) {
let
inThrottle;
return
(
...args
) =>
{
if
(!inThrottle) {
func
(...args); inThrottle =
true
;
setTimeout
(
() =>
(inThrottle =
false
), limit); } }; }