13 lines
250 B
JavaScript
13 lines
250 B
JavaScript
|
function throttle(callback, limit) {
|
||
|
var waiting = false;
|
||
|
return function () {
|
||
|
if (!waiting) {
|
||
|
callback.apply(this, arguments);
|
||
|
waiting = true;
|
||
|
setTimeout(function () {
|
||
|
waiting = false;
|
||
|
}, limit);
|
||
|
}
|
||
|
};
|
||
|
}
|