/**
*
*@param func {Function} 实际执行的函数
*@param delay {Number} 延迟阈值,毫秒单位
*@return {Function}
*/functiondebounce(func,delay){// set a timer for setTimeout
lettimer//return the function that will be triggered after delay milliseconds
returnfunction(){// pass context and argument to func
letcontext=thisletargs=arguments// each time this function is invoked,then clear timeout and don't fired func
clearTimeout(timer)//The function will be called after it stops being called for
// N milliseconds.
timer=setTimeout(function(){func.apply(context,args)},delay)}}
/**
*
* @param func {Function} 要进行处理的函数
* @param delay {Number} 延迟阈值,毫秒单位
* @returns {Function}
*/functiondebounce(func,delay){// set a timer for setTimeout
lettimer//return a function that will be triggered after delay milliseconds
return(...args)=>{// each time this function is invoked,then clear timeout and don't fired func
clearTimeout(timer)//The function will be called after it stops being called for
// N milliseconds.
timer=setTimeout(()=>{timer=nullfunc(...args)},delay)}}