xxm-test-js
Version:
xxm-js通用js工具(utils)库
23 lines • 662 B
JavaScript
;
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