当前位置:网站首页>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.
边栏推荐
猜你喜欢
随机推荐
js中的闭包
【Harmony OS】【ArkUI】ets开发 图形与动画绘制
汇编题答案
私域流量时代来临,电商企业如何布局?
DC-4靶场搭建及渗透实战详细过程(DC靶场系列)
正则表达式绕过
肖sir__面试接口测试
install ambari
【软件工程之美 - 专栏笔记】35 | 版本发布:软件上线只是新的开始
接口测试框架实战(四)| 搞定 Schema 断言
2022 the first of the new league henan (4) : zhengzhou university of light industry G - maze
关于#sql#的问题,如何解决?
MCM箱模型建模方法及大气O3来源解析
2022/08/02 学习笔记 (day22) 多线程
工程水文学试题库
测开:项目管理模块-项目curd开发
工程水文学知识点
社交电商:链动2+1模式,为什么能在电商行业生存那么久?
种草一个让程序员男友编程时,记住一辈子的 IDEA 神仙插件!
ORACLE中文乱码