// es6 实现方式 function debounce(fn,wait){ let timer; return function(fn,wait){ if(timer){ clearTimeout(timer) timer = null } let _this = this let arg = arguments timer = setTimeout(function(){ fn.apply(arg,_this) },wait) } } debounce(function(){ console.log('123') },2000) // ts 实现方式