js 函数节流

//es6语法

export function debounce(func, delay) { let timer //返回一个函数,并拿到参数 return function (...args) { if (timer) { clearTimeout(timer) } timer = setTimeout(() => { func.apply(this, args) }, delay) } }
//简单实现

var
debounce = function(idle, action){ var last return function(){ var ctx = this, args = arguments clearTimeout(last) last = setTimeout(function(){ action.apply(ctx, args) }, idle) } }

 

posted @ 2018-09-28 16:37  abcByme  阅读(453)  评论(0编辑  收藏  举报