console
function Debance(cb, delay = 500) {
let timeId = null
return function(...args) {
if(timeId) {
clearTimeout(cb)
}else {
timeId = setTimeout(() => {
cb.call(this,...args)
},delay)
}
}
}
function Throttle(cb, delay = 500) {
let flag = false
return function(...args) {
if(!flag) return
setTimeout(() => {
cb.call(this, ...args)
flag = true
}, delay)
flag = false
}
}
const oInput = document.querySelector('input')
oInput.addEventListener('input', Throttle(function() {
console.log('xxxxx')
}, 2000))
<input />