防抖函数 模板~
防抖函数一直是面试的重点,特此整理,写个百八十遍~
<body>
<div id="button">点击按钮</div>
<script>
const button = document.getElementById('button');
function payMoney() {
console.log('我要支付啦');
}
function deBounce(func, delay) {
let timer;
return function () {
clearTimeout(timer);
let context = this;
let args = arguments;
timer = setTimeout(function () {
func.apply(context, args);
}, delay);
};
}
</script>
</body>
参考 :哔哩哔哩=》》技术蛋老师

浙公网安备 33010602011771号