手撕防抖节流
function debounce(fn, delay){
let timer = null
return function(){
clearTimeout(timer)
timer = setTimeout(() => {
fn.apply(this, arguments)
timer = null
}, delay)
}
}
function throttle(fn, delay){
let timer = null
return function(){
if(timer) return
timer = setTimeout(() => {
fn.apply(this, arguments)
timer = null
}, delay)
}
}
登录为什么用token,存在哪里,有其他的吗,有什么优劣