//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 lastreturn function(){var ctx = this, args = argumentsclearTimeout(last)last = setTimeout(function(){action.apply(ctx, args)}, idle)}
}
更多专业前端知识,请上 【猿2048】www.mk2048.com