var count = 0;
function myFunc() {
count++;
console.log(count);
}
var func = throttle(myFunc, 100);
window.onresize = function () {
func();
}
function throttle(fn, delay) {
var timer = null;
return function () {
var context = this,
args = arguments;
clearTimeout(timer);
timer = setTimeout(function () {
fn.apply(context, args);
}, delay);
}
}
函数节流闭包封装
最新推荐文章于 2024-06-07 10:59:46 发布