function debouce(fn, deay){
let timer = null;
return function(){
clearTimeout(timer)
timer = setTimeout(() => {
fn.apply(this, arguments)
}, deay)
}
}
function throttle(fn, time){
let lastTime = 0;
return function(){
const nowTime = new Date().getTime()
if( nowTime - lastTime >= time) {
fn.apply(this, arguments);
lastTime = nowTime
}
}
}
function testDebouce(a) {
console.log('debounce', a)
}
let aa = debouce(testDebouce, 300)
aa(1)
setTimeout(() => aa(2), 400)
setTimeout(() => aa(3), 400)
function testThrottle(a) {
console.log('throttle', a)
}
let bb = throttle(testThrottle, 4)
bb(1)
setTimeout(() => bb(2), 4)
setTimeout(() => bb(3), 4)
console