节流函数(闭包第二种形式传参),用来限制函数执行

    技术2022-07-10  147

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title></title> </head> <body> <script> // 窗口大小变化 window.onresize = throttle(function () { console.log('大家好!!!'); }, 2000); // 传参闭包 节流 function throttle(fn, delay) { //通过节流延迟fn执行频次 var timer = null; return function () { clearTimeout(timer); timer = setTimeout(fn, delay); } } </script>
    Processed: 0.012, SQL: 12