|
@@ -171,16 +171,19 @@ export function jsonp2(url, params, callbackName = 'jsonp_callback') {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
-export function throttleAdvanced(fn, delay) {
|
|
|
|
|
|
|
+export function throttleAdvanced(func, delay = 5000) {
|
|
|
let lastExecTime = 0; // 记录上次成功执行的时间戳
|
|
let lastExecTime = 0; // 记录上次成功执行的时间戳
|
|
|
- return function(...args) { // 使用剩余参数接收所有传入参数
|
|
|
|
|
- const now = Date.now(); // 获取当前时间戳
|
|
|
|
|
- // 如果当前时间减去上次执行时间大于等于设定的延迟,则执行函数
|
|
|
|
|
- if (now - lastExecTime >= delay) {
|
|
|
|
|
- // 使用 apply 确保函数内部的 this 指向正确,并传递参数
|
|
|
|
|
- fn.apply(this, args);
|
|
|
|
|
|
|
+
|
|
|
|
|
+ return function(...args) {
|
|
|
|
|
+ const currentTime = Date.now(); // 获取当前时间戳
|
|
|
|
|
+
|
|
|
|
|
+ // 如果当前时间距离上次执行时间已经超过了设定的延迟时间
|
|
|
|
|
+ if (currentTime - lastExecTime >= delay) {
|
|
|
|
|
+ // 使用 apply 确保函数上下文和参数正确传递
|
|
|
|
|
+ console.log(11111)
|
|
|
|
|
+ func.apply(this, args);
|
|
|
// 更新最后一次执行的时间戳为当前时间
|
|
// 更新最后一次执行的时间戳为当前时间
|
|
|
- lastExecTime = now;
|
|
|
|
|
|
|
+ lastExecTime = currentTime;
|
|
|
}
|
|
}
|
|
|
// 如果时间间隔未到,则什么都不做,忽略此次调用
|
|
// 如果时间间隔未到,则什么都不做,忽略此次调用
|
|
|
};
|
|
};
|