acdr-ui/dist/dev/mp-weixin/modules/mall/sheep/helper/throttle.js
2024-10-01 09:15:35 +08:00

21 lines
423 B
JavaScript

"use strict";
let flag;
function throttle(func, wait = 500, immediate = true) {
if (immediate) {
if (!flag) {
flag = true;
typeof func === "function" && func();
setTimeout(() => {
flag = false;
}, wait);
}
} else if (!flag) {
flag = true;
setTimeout(() => {
flag = false;
typeof func === "function" && func();
}, wait);
}
}
exports.throttle = throttle;