console
let inp = document.getElementById('inp')
inp.addEventListener('input', debounce(search, 500))
function debounce(fn, wait) {
let timer = null
return () => {
clearTimeout(timer)
timer = setTimeout(function () {
arr = [1, 2, 5]
fn.call(this, ...arr)
}, wait)
}
}
function search(a, b, c) {
console.log(a, b, c)
}
window.addEventListener('resize', throttle(sayHi, 500))
function sayHi(e) {
console.log(e.target.innerWidth, e.target.innerHeight);
}
function throttle(fn, wait) {
let timer = null;
return function(){
if (timer) {
return;
}
timer = setTimeout(() => {
fn.call(this,...arguments)
timer = null
}, wait)
}
}
<input id="inp">