获得徽章 0
你们的副业到底是啥阿,我giao
5
java大佬能不能说一下这个为啥呀
向大叔学习于2024-08-30 15:08发布的图片
9
赞了这篇沸点
#每天一个知识点#
js 实现防抖和节流函数

1. 防抖函数(Debounce)
function debounce(func, delay) {
let timer;
return function(...args) {
const context = this;
clearTimeout(timer);
timer = setTimeout(() => {
func.apply(context, args);
}, delay);
};
}

// 使用示例
window.addEventListener('resize', debounce(() => {
console.log('Window resized');
}, 500));

2. 节流函数(Throttle)
function throttle(func, interval) {
let lastTime = 0;
return function(...args) {
const now = Date.now();
if (now - lastTime >= interval) {
func.apply(this, args);
lastTime = now;
}
};
}

// 使用示例
window.addEventListener('scroll', throttle(() => {
console.log('Window scrolled');
}, 500));
展开
评论
web前端开发 @未来互联网科技有限公司
转哪行收入才能不比现在行业低嘞?
4
web前端开发 @未来互联网科技有限公司
大佬们,有没有稳定使用tg的方法啊
18
web前端开发 @未来互联网科技有限公司
web前端开发 @未来互联网科技有限公司
不懂就问,你们都在搞什么副业呀?
19
web前端开发 @未来互联网科技有限公司
web前端开发 @未来互联网科技有限公司
web前端开发 @未来互联网科技有限公司
下一页
个人成就
文章被点赞 4
文章被阅读 2,323
掘力值 74
收藏集
3
关注标签
34
加入于