代码如下:
function debounce(fn, delay = 300) {
let timer = null
return function () {
let context = this
let args = arguments
if (timer) {
clearTimeout(timer)
}
timer = setTimeout(function () {
fn.apply(context, args)
}, delay)
}
}