// throttle的简易实现
// function throttle(func, duration) {
// 在这里编写具体实现
// }
// window.addEventListener('scroll', throttle(func, 50), false);
function throttle (func, duration) {
this.latest = 0
return function () {
let cur = +new Date()
if (duration < cur - this.latest) {
func.apply(this, arguments)
this.latest = cur
}
}
}
const func = function () {
console.log('scroll')
}
window.addEventListener('scroll', throttle(func, 50), false)