徐徐爱coding
  • 首页
  • 爱情买卖
  • 导航
  • 私语
  • 友情链接
  • 关于
    关于本站
    知识库
    弹钢琴
徐徐爱coding

徐徐爱coding

徐徐爱coding是一个个人博客站点,记录编程经历的点点滴滴,分享自己的所见与所得,坚持自己的初心,践行自己的梦想生活不是等着暴风雨过去,而是学会在风雨中跳舞!

Copyright © 2023 徐徐爱coding All Rights Reserved.
陕公网安备61019602000456陕ICP备2023007787号-2

网站已稳定运行

节流与防抖

节流与防抖

徐徐
前端
#javascript
3 热度0 评论0 点赞
发布于2023-09-28 00:00:17
🌺前言
前端手动实现节流防抖

节流

javascript
function debounce(fn, wait) {
     let timer = null
        return function () {
           if (timer) clearTimeout(timer)
                timer = setTimeout(() => {
                    fn.call(this, arguments)
                }, wait)
            }
        }

防抖

javascript
function throttle(fn, wait) {
            let timer = null
            return function () {
                if (!timer) {
                    timer = setTimeout(() => {
                        event()
                        timer = null
                    }, wait)

                }
            }
        }

目录

  • 节流
  • 防抖
文章最后更新于 2024-08-30 16:39:56
作者:徐徐
版权声明:转载请注明文章出处
留言
暂无数据

~~空空如也