当前位置:网站首页>JS closure knowledge
JS closure knowledge
2022-07-27 21:05:00 【Liupengyuan LPY】
One : The three elements of closures :
1. Functions are nested
2. Internal functions must reference local variables of external functions
3. External functions must call
Two : Closure advantages :
1. Can be outside the function Access to internal variables ( Originally, local variables inside the function cannot be accessed outside the function , But the function inside the function can access the local variables in this function )
2. Extend the life cycle of local variables ( The essence :)
var fnn2 = fn() The internal variable was originally executed once a It should be destroyed , But because it is assigned a value, there is a reference relationship , Local variables are always saved
3、 ... and : Disadvantages of closures
1. Abusing closures , Its execution environment has always been Cause memory overflow And memory leaks
Four : The life cycle of closure
1. produce : Closures complete nested functions ( Three elements of establishment ) It occurs when ( Instead of calling )
2. Death : When a variable that receives a closure is called a garbage object (null)
5、 ... and : Solutions to closure shortcomings
1. Memory leak : Memory could not be released
2. out of memory : Memory burst
3. solve :f=null ; Let the closure mechanism clear ,f Refers to the variable that receives the external function
6、 ... and : Closure scope : Start looking up where the function is created 
1. Function is returned as a return value 
2. The function is passed as an argument 
7、 ... and : Application scenarios of closures
1. Do the cache 
2. throttle , Shake proof : Limit the number of executions of the function
3. throttle throttle: Reduce the trigger frequency for a period of time ( Specify how long it can be triggered )
① Timer version 
② Timestamp version :
4. Shake proof debounce: adopt setTimeout The way , Within a time interval of , Turn multiple triggers into one trigger , Only for the last time
Be careful this Points and parameters arguments problem 
边栏推荐
- DJI内推码(一码一用,2022年7月26日更新)
- 一文读懂Plato Farm的ePLATO,以及其高溢价缘由
- Diffuse reflection of QT OpenGL light
- 程序中的地址如何转换?
- Hexagon_ V65_ Programmers_ Reference_ Manual(9)
- Things about stack migration
- 82.(cesium篇)cesium点在3d模型上运动
- [today in history] July 27: model testing pioneer was born; Microsoft acquires qdos; The first laser typesetting Chinese newspaper
- js闭包知识
- sscanf 导致地址越界
猜你喜欢
Rk3399 platform development series explanation (process part) 15.36, understanding process and collaboration process

程序中的地址如何转换?

自动化测试----unittest框架

Source Insight 4.0使用介绍

Global styles and icons

NPDP | what kind of product manager can be called excellent?

knife4j通过js动态刷新全局参数

LeetCode-136-只出现一次的数字

Kingbasees heterogeneous database migration guide (4. Application migration process)
![重复的DNA序列[hash判定重复+滑动窗口+二进制编码之位运算]](/img/ed/6f4da22e86b44935fc84e3b4901c48.png)
重复的DNA序列[hash判定重复+滑动窗口+二进制编码之位运算]
随机推荐
重复的DNA序列[hash判定重复+滑动窗口+二进制编码之位运算]
How to make personalized recommendations instantly accessible? Cloud native database gaussdb (for redis) to help
Overview of understanding the physical layer of transmission media
go --- air自动重新编译
Beijing / Shanghai / Guangzhou / Shenzhen dama-cdga/cdgp data governance certification registration conditions
怎样实现文档协同?
Hexagon_ V65_ Programmers_ Reference_ Manual(8)
Qt OPenGL 光的漫反射
Hexagon_ V65_ Programmers_ Reference_ Manual(7)
A method of MCU log output
如何让个性化推荐即刻触达?云原生数据库GaussDB(for Redis)来助力
Uncaught SyntaxError: redeclaration of let page
LeetCode每日一练 —— 203. 移除链表元素
[numpy] array index and slice
[numpy] broadcast mechanism
基于文件上传漏洞获得网站 shell 权限
Force deduction solution summary 592 fraction addition and subtraction
北京/上海/广州/深圳DAMA-CDGA/CDGP数据治理认证报名条件
认识网络模型网络模型概述
SQL coding bug