当前位置:网站首页>A simple understanding of closures
A simple understanding of closures
2022-06-11 16:59:00 【The mighty moon】
Closures open a channel for accessing the internal scope of a function outside the function , Normally, the scope variables inside the function cannot be accessed outside the function .
The representation judges whether it is a closure :
1. Function nested function
2. Internal functions are return
3. The inner function calls the local variable of the outer function
Application scenarios :
1. Function as return value
function fn() {
var count = 1
function fn2() {
console.log(count)
}
// Returns a function , This function is a closure
return fn2
}
//f1 Namely box function
var f1 = fn()
//5 Call... In seconds f1 function , Can still print count Value , Closures allow local variables to reside in memory
setTimeout(function () {
f1()
}, 5000) function fn() {
var count = 1
function fn2() {
count += 1
return count
}
return fn2
}
var f1 = fn()
console.log(f1())
console.log(f1())2. The function is passed as an argument ( Callback function )
边栏推荐
- Drug evaluation index
- (validation file) validatejarfile report errors
- Weekly recommended short video: rookie CEO talks about the new logistics track in the future
- How to store tree structure in database
- Oracle database merge row records, wmsys WM_ Use of the concat function and group in MySQL_ Use and comparison of concat (ID).
- 2022g1 industrial boiler stoker test questions and simulation test
- LeetCode-384. 打乱数组
- ShellBrowser . NET Crack
- Learn about Prometheus from 0 to 1
- Config: user attribute configuration framework
猜你喜欢

GemBox.Bundle 43.0 Crack

Analysis report on future development trend and investment suggestions of global and Chinese soybean protein industry 2022-2028

The micro service failed to connect to the cloud sentinel console and the link blank problem occurred after the connection was successful (resolved)

每周推荐短视频:菜鸟CEO谈未来物流新赛道

Message queue push / pull mode Learning & ActiveMQ and JMS learning

Common tools and commands for information collection

Science popularization genius on the left, madman on the right

Elasitcsearch basic learning notes (1)

Why does chip design also need "Craftsmanship"?

基于文本驱动用于创建和编辑图像(附源代码)
随机推荐
GemBox. Bundle 43.0 Crack
启牛商学院给的证券账户是安全的吗?开户收费吗
Is the stock account recommended by qiniu safe? Is it reliable
How to disable the notebook's own keyboard after the notebook is connected to an external keyboard
Global and China Mobile Network Optimization (MnO) industry development panoramic survey and Investment Strategy Research Report 2022-2028
Why does chip design also need "Craftsmanship"?
JVM 的组成
【pytest学习】pytest 用例执行失败后其他不再执行
2022起重机司机(限桥式起重机)考试题模拟考试题库及模拟考试
2022年R1快開門式壓力容器操作考試題庫及模擬考試
tornado环境搭建及基本框架搭建——熟悉的hello world
做跨境电商卖什么产品好?热销类目有哪些?
Learn about Prometheus from 0 to 1
(validation file) validatejarfile report errors
golang中的异常处理和异常使用
The micro service failed to connect to the cloud sentinel console and the link blank problem occurred after the connection was successful (resolved)
美团获得小样本学习榜单FewCLUE第一!Prompt Learning+自训练实战
Solr (II) Solr adds core and dependent package path
《DAMA数据管理知识体系指南》:章节分值占比
select into from 和 insert into select 区别