アンチシェイクとスロットルは、フロントエンド開発中のパフォーマンス最適化に使用される一般的な方法です。
防振機能(デバウンス):
function _debounce(fn、delay){
var delay = delay || 200;
数時間でした。
return function(){
var th = this;
var args = arguments;
if(timer){
clearTimeout(timer);
}
timer = setTimeout(function(){
timer = null;
fn.apply(th、args);
}、delay);
}。
}
スロットル機能(スロットル):
function _throttle(fn、interval){
var last;
var timer;
変数の間隔=間隔|| 200;
return function(){
var th = this;
var args = arguments;
var now = + new Date();
if(最後&&現在-最後<間隔){
clearTimeout(timer);
timer = setTimeout(function(){
last = now;
fn.apply(th、args);
}、interval);
} else {
last = now;
fn.apply(th、args);
}
}
}