防抖

function debounce (handle,delay){
var timer = null;
return function () {
clearTimeout(timer)
timer = setTimeout(() => {
handle.apply(this, arguments)
},delay)
}
}
利用了闭包和定时器来延缓函数的执行,最常见的就是应用在input框中

posted @ 2019-03-10 17:15  那个村  阅读(119)  评论(0)    收藏  举报