美文网首页
2021-02-28

2021-02-28

作者: 转移到CSDN名字丹丹的小跟班 | 来源:发表于2021-03-01 08:45 被阅读0次

js

所谓防抖,就是指触发事件后在 n 秒内函数只能执行一次,如果在 n 秒内又触发了事件,则会重新计算函数执行时间。
防抖核心函数

function debounce(fn, delay) {
  let timeout = null;
  return function() {
    // 保存this和参数
    let context = this
    let args = arguments
    if(timeout) {
      clearTimeout(timeout) //频繁触发则清除上一次,只执行最后一次
    }
    timeout = setTimeout(() => {
      fn.apply(context, args)
    },delay)
  }
}

所谓节流,就是指连续触发事件但是在 n 秒中只执行一次函数。节流会稀释函数的执行频率。
节流核心函数

function throttle(fn, timer) {
    let start = new Date()
    let timeout = null
    return function() {
        let end = new Date
        let context = this
        clearTimeout(timeout)
        if (end - start >= timer) {
            fn.apply(context)
            start = end
        }
    }
}

get 请求传参长度的误区

  • HTTP 协议 未规定 GET 和 POST 的长度限制
  • GET 的最大长度显示是因为 浏览器和 web 服务器限制了 URI 的长度
  • 不同的浏览器和 WEB 服务器,限制的最大长度不一样
  • 要支持 IE,则最大长度为 2083byte,若只支持 Chrome,则最大长度 8182byte

相关文章

网友评论

      本文标题:2021-02-28

      本文链接:https://www.haomeiwen.com/subject/aangfltx.html