
获得徽章 4
- 关于节流的问题
let timer,start ;
export function throttle(method, delay) {
let args = arguments;
return function loop() {
let self = this, now = Date.now();
start = start || now;
clearTimeout(timer);
if(now - start >= delay) {
method.apply(self, args);
start = now;
}else {
// 兜底执行一次
timer = setTimeout(function() {
loop.apply(self, args);
}, delay + 10);
}
}
}
timer 和 start 不提到全局真的无法使用展开1点赞