UNPKG

xxm-test-js

Version:
23 lines 662 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.throttle = throttle; function throttle(func, limit) { let lastFunc = null; let lastRan = 0; return function (...args) { const time = Date.now(); if (time - lastRan >= limit) { func(...args); lastRan = time; lastFunc = null; } else if (lastFunc === null) { lastFunc = setTimeout(() => { func(...args); lastRan = Date.now(); lastFunc = null; }, limit - (time - lastRan)); } }; } //# sourceMappingURL=throttle.js.map