SOURCE

console 命令行工具 X clear

                    
>
console
// 节流可用于滚动监听
function throttle(fn, during) {
    let previous = 0;
    return function(...args) {
        let that = this;
        let now = Date.now();
        if (now - previous > during){
            fn.apply(that, args);
            previous = now;
        }
    }
}

window.addEventListener('scroll', throttle((e) => {
    console.log(document.documentElement.scrollTop)
    console.log(document.documentElement.clientHeight)
}, 1000))

// 防抖
function debounce(during, fn) {
    let timer = null;
    return function () {
        clearTimeout(timer);
        timer = setTimeout(() => {
            fn.apply(this, arguments);
        }, during)
    }
}

document.documentElement.addEventListener('click', debounce(1000, (e) => {
    console.log(e.target)
}))
<div class="box"></div>
.box{
    width: 200px;
    height: 2000px;
    background-color: pink
}