节流
const throttle = (fn
, interval
) => {
let last
= Date
.now()
return function () {
const self
= this
const args
= arguments
const now
= Date
.now()
if (now
- last
> interval
) {
last
= now
fn
.apply(self
, args
)
}
}
}
防抖
const debounce = (fn
, interval
) => {
let timer
= null
return function () {
const self
= this
const args
= arguments
if (timer
) {
clearTimeout(timer
)
}
setTimeout(() => {
fn
.apply(self
, args
)
}, interval
)
}
}
转载请注明原文地址:https://blackberry.8miu.com/read-31456.html