感觉js高程中对于节流的定义和平常看到的博客中对于节流的定义不太一样呢?感觉这个定义像是防抖,跟underscore中的debounce方法类似,而且我也偏向于认为这种思想称为防抖,请大佬指正
这是高程中对于节流的定义和代码
function throttle(method, context) {
clearTimeout(method.tId);
method.tId= setTimeout(function(){
method.call(context);
}, 100);
}
一些博客里看到的对于防抖的定义和实现
//防抖的代码实现
function debounce(fn, delay){
let timer = null;
return function() {
let context = this;
let args = arguments;
clearTimeout(timer);
timer = setTimeout(function(){
fn.apply(context, args);
}, delay)
}
}
节流和防抖都属于节流。
或者说,throttle和debounce是节流技术的两种相似但稍有差别的实现。