当前位置:网站首页>closures in js
closures in js
2022-08-03 04:32:00 【weixin_46051260】
Concept: A closure is a function that has access to a variable in the scope of another function
1) Features of closures
- Function Nested Function
- A function can reference external parameters and variables
- Parameters and variables will not be garbage collected
2) Advantages of closures
- Variables reside in memory for long periods of time
- Avoid pollution of global variables
3) Disadvantages of closures
Variables are always kept in memory, too many closures may lead to memory leaks
4) Closure scene
- Callbacks
In timers, event listeners, Ajax requests, cross-window communication, Web Workers, or any async, as long as you use a callback function
, you're actually using a closure. - Execute function immediately
- Anti-shake
The callback is executed after n seconds after the event is triggered. If it is triggered again within these n seconds, the timer will be restarted.
边栏推荐
- Shell条件语句判断
- 12.机器学习基础:评估机器学习模型
- excerpt from compilation book
- Shenzhen Offline Registration|StarRocks on AWS: How to conduct rapid and unified analysis of real-time data warehouses
- 4.深度学习的几何解释与梯度的优化
- 接口测试框架实战(二)| 接口请求断言
- 我将GuiLite移植到了STM32F4开发板上
- 自考六级雅思托福备战之路
- The flink sql task is changed, and after adding several fields to the sql, an error occurs when restoring from the previously saved savepoint.
- JS底层手写
猜你喜欢
随机推荐
社交电商:流量红利已尽,裂变营销是最低成本的获客之道
MCM箱模型建模方法及大气O3来源解析
MySQL 删除表数据,重置自增 id 为 0 的两个方式
IDEC和泉触摸屏维修HG2F-SS22V HG4F软件通信分析
肖sir ——自动化讲解
Windows 安装PostgreSQL
MySql 创建索引
WebSocket的实际应用
三丁基-巯基膦烷「tBuBrettPhos Pd(allyl)」OTf),1798782-17-8
计网试卷概念
汇编书摘抄
正则表达式与绕过案例
超好用的画图工具推荐
ORACLE中文乱码
【Harmony OS】【FAQ】鸿蒙问题合集1
工程水文学试题库
汇编题答案
【Harmony OS】【ARK UI】Date 基本操作
Mysql如何建立索引实现语句优化
接口测试 Mock 实战(二) | 结合 jq 完成批量化的手工 Mock









