美文网首页
11-函数防抖

11-函数防抖

作者: 仰望_IT | 来源:发表于2019-05-15 11:27 被阅读0次
    • 1.什么是函数防抖[debounce]?
      • 函数防抖是优化高频率执行js代码的一种手段
      • 可以让被调用的函数在一次连续的高频操作中只被调用一次
    • 2. 函数防抖的作用
      • 减少代码执行次数, 提升网页性能
    • 3. 函数防抖应用场景
      • oninput / onmousemove / onscroll / onresize 等事件
        let oInput = document.querySelector("input");
        let timerId = null;
    
        oInput.oninput = function () {
            timerId && clearInterval(timerId);
            timerId = setTimeout(function () {
                console.log("发生网络请求");
            }, 1000);
        }
    

    相关文章

      网友评论

          本文标题:11-函数防抖

          本文链接:https://www.haomeiwen.com/subject/iptpaqtx.html