js 函数节流

mac2022-06-30  25

//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) } }

 

更多专业前端知识,请上 【猿2048】www.mk2048.com
最新回复(0)