// 函数防抖
export function debounce (func, delay = 300, immediate = false) {
let timer = null
return function () {
if (timer) {
clearTimeout(timer)
}
if (immediate && !timer) {
func.apply(this, arguments)
}
timer = setTimeout(() => {
console.log(this, arguments)
func.apply(this, arguments)
}, delay)
}
}
网友评论