当前位置:网站首页>简单手写debounce函数
简单手写debounce函数
2022-06-28 05:40:00 【Joey_Tribiani】
function debounce(cb, timeout = 300) {
// 闭包一个上次触发时间
let lastEmitTime;
return function () {
// 每次调用更新上次触发时间
lastEmitTime = new Date().valueOf();
setTimeout(() => {
// 设置的timeout时间过后去比较最后一次调用时间是否已经是超过了设置的timeout 超过了就调用callback
const currentTime = new Date().valueOf();
if (currentTime - lastEmitTime >= timeout) {
cb(...arguments);
}
}, timeout);
};
}
边栏推荐
猜你喜欢

Where is the era bonus for developers?

Create NFS based storageclass on kubernetes

Prime mover × Cloud primordial is making sound, reducing cost and increasing efficiency lecture hall

sklearn 特征工程(总结)

2022 new version NFT source code source code of China meta universe digital collection art trading platform

Solution of dam safety automatic monitoring system for medium and small reservoirs

jsp连接Oracle实现登录注册

JS中的链表(含leetcode例题)<持续更新~>

Jenkins持续集成1

Filecoin hacker song developer competition
随机推荐
电商转化率这么抽象,到底是个啥?
Operation of 2022 power cable judgment question simulation examination platform
数据中台:数据治理的建设思路以及落地经验
Data warehouse: DWS layer design principle
5g network overall architecture
Ape pink ape power - Developer activity attack!
Leecode question brushing-ii
MySQL 45 talk | 05 explain the index in simple terms (Part 2)
Detailed usage configuration of the shutter textbutton, overview of the shutter buttonstyle style and Practice
Official answers to the "network security" competition questions of the 2022 national vocational college skills competition
[JVM] - Division de la mémoire en JVM
TypeScript接口
Syn retransmission caused by IPVS
How to develop the language pack in the one-to-one video chat source code
Qtcanpool knowledge 07:ribbon
如何在您的Shopify商店中添加实时聊天功能?
密码学笔记
Prime mover × Cloud primordial is making sound, reducing cost and increasing efficiency lecture hall
qtcanpool 知 05:无边框
小球弹弹乐