知食记
搜索文档…
知食记
思维导图
归档
博客
🎃CSS
CSS基础
CSS3
SCSS
🎉JavaScript
JS 概念
JS陷阱
JS开发知识点
实现JS常见函数
Debounce
Throttle
Call, Apply, Bind
type
深拷贝
isEuqal
数组乱序
数组去重
实现 merge
数组flat
实现 map
数组filter
模拟new
模拟实现async
模拟instance of
Object.create(null)与{}
实现promisify
实现Promise.all
实现Promise.race
实现Promise.resolve/reject
实现Promise.finnaly
实现Promise
实现parseInt
实现foreach
实现Object keys
实现JS 常见操作函数
JS Worker
ES6
ES6 函数
Typescript
V8
🕹️框架
Vue
Vue3
React
React-Redux
React Hooks
Nuxt
Koa2
🎯算法
算法与数据结构
🎁HTML
DOM
SVG
🏈计算机网络
浏览器
计算机网络
🥊前端生态
Webpack
Babel
Fetch
Axios
Npm
Yarn
业务开发
微前端
Hexo
🏀后端
Node
Java
Python
🕹️面试
面试真经
To-do
🤖开源
开源项目
🧸其他
Linux
Git
正则
设计模式
计算机理论
Group 1
由
GitBook
提供支持
Throttle
节流函数总结
定义
throttle和debounce非常像。唯一的区别就是,throttle会设置固定的时间间隔,即使事件还没有间断大于某个阈值,只要时间间隔到了,就会执行一次。
简单来说,throttle是在debounce最后会执行一次的基础上,穿插在中间固定时间间隔执行。
ES6实现
1
function
throttle
(
fn
,
wait
)
{
2
let
timeout
,
lastTime
=
0
3
return
(
...
args
)
=>
{
4
const
currentTime
=
Date
.
now
()
5
if
(
current
>=
lastTime
+
wait
){
6
lastTime
=
current
7
fn
(
...
args
)
8
}
else
{
9
clearTimeout
(
timeout
)
10
timeout
=
setTimout
(()
=>
fn
(
...
args
),
wait
)
11
}
12
}
13
}
Copied!
以前
Debounce
下一个
Call, Apply, Bind
最近更新
2yr ago
复制链接
内容
定义
ES6实现