当前位置:网站首页>Understanding of closures
Understanding of closures
2022-06-26 07:54:00 【Forge ahead and have a bright future】
What is a closure ? Usually implemented in nested functions , It refers to variables in the scope of a function that refer to other functions . It is used to enable external function methods to get the variables inside the function . It is a bridge linking the function inside and outside .
The benefits of closures :1、 Keep variables in memory all the time 2、 So that the external can get the internal variables of the function ;
function f1(){
var n = 1;
return function(){
console.log(n);
n += 1;
}
}
var f2 = f1()
f2() //1
f2() //2return Anonymous function of is defined by global variable f2 quote , This anonymous function will not be destroyed , therefore n It will not be destroyed .
What to pay attention to : Unnecessary use of closures can lead to excessive memory consumption , Even lead to memory leaks .
Reference resources : Study Javascript Closure (Closure) - Ruan Yifeng's Weblog
边栏推荐
- OSPF design principles, commands take H3C as an example
- Redis(5)----浅谈压缩列表
- [UVM foundation] UVM_ Driver member variable req definition
- PyTorch-12 GAN、WGAN
- Multi interface switching in one UI of QT
- What are the characteristics of digital factory in construction industry
- Flower instruction WP
- B站增量数据湖探索与实践
- buuresevewp
- JS event loop mechanism
猜你喜欢
![Jemter stress test - visualization tool - [usage]](/img/b1/3c367b690bbc16ae5a3e9e2c85af73.png)
Jemter stress test - visualization tool - [usage]

Power apps application practice | easily develop employee leave attendance management applet with power apps

What is the difference between bone conduction earphones and ordinary earphones? Advantages of bone conduction earphones

Basic use of swiperefreshlayout, local refresh of flutterprovider

Important reference indicators for data center disaster recovery: RTO and RPO

我想造SQL数据(存储结构)

Baoyan postgraduate entrance examination interview - Network

Redis (4) -- Talking about integer set
![[UVM basics] TLM common data receiving and sending and data receiving examples](/img/4f/6c6e8b26124ba042f949291b944c3d.jpg)
[UVM basics] TLM common data receiving and sending and data receiving examples

OSPF design principles, commands take H3C as an example
随机推荐
Redis (4) -- Talking about integer set
Arrangement and insertion structure
What is the five levels of cultivation of MES management system
Orderly arrangement
buuresevewp
Exploration and practice of incremental data Lake in station B
The difference between setstoragesync and setstorage
Google Earth Engine(GEE) 01-中输入提示快捷键Ctrl+space无法使用的问题
buuresevewp
Getdrawingcache of view is empty. Solution: interview questions for Android audio and video development
Jemter 壓力測試 -基礎請求-【教學篇】
Can the warehouse management system help enterprises reduce storage costs
Area of Blue Bridge Cup 2 circle
Solve psycopg2 NotSupportedError: PQconninfo not available in libpq < 9.3
有序排列
1010. song backtracking with total duration divisible by 60
Uniapp scrolling load (one page, multiple lists)
Children play games (greed, prefix and) - Niuke winter vacation training camp
Golang collaboration and channel usage
Record the dependent installation problems encountered in building the web assets when developing pgadmin