当前位置:网站首页>什么是闭包?
什么是闭包?
2022-04-23 06:18:00 【十九(一拖再拖)】
闭包:调用一个函数作用域中变量的函数称为闭包。通常发生在嵌套函数中。
例如:
function aa(){
var a = 100;
function bb(){
return ++a;
}
return bb;
}
var cc = aa();
cc();
console.log(cc());
// 输出:102
如果不是闭包,则:
function aa(){
var a = 100;
return ++a;
}
aa();
aa();
console.log(aa());
// 输出:101
调用多次函数,值也只会增加一次。
版权声明
本文为[十九(一拖再拖)]所创,转载请带上原文链接,感谢
https://blog.csdn.net/qq_41974199/article/details/115713995
边栏推荐
猜你喜欢
Gather, unsqueeze and other operators when PTH is converted to onnx
传输层重要知识(面试,复试,期末)
quill-editor图片缩放、在一个页面使用多个富文本框、quill-editor上传图片地址为服务器地址
网络层重要知识(面试、复试、期末)
项目文件“ ”已被重命名或已不在解决方案中、未能找到与解决方案关联的源代码管理提供程序——两个工程问题
el-date-picker中自定义快捷选项picker-options,动态设置禁用日期
How to improve the service efficiency of the hotel without blind spots and long endurance | public and Private Integrated walkie talkie?
Jiangning hospital DMR system solution
Intuitive understanding of torch nn. Unfold
Typora操作技巧说明(一).md
随机推荐
PyTorch 22. Pytorch common code snippet collection
Intuitive understanding of torch nn. Unfold
使用proteus仿真STM32超声波SRF04测距!Code+Proteus
使用el-popconfirm和el-backtop不生效
自定义classloader并实现热部署-使用loadClass
el-table 横向滚动条固定在可视窗口底部
The people of Beifeng have been taking action
Beifeng communication helps Zhanjiang fire brigade build PDT wireless communication system
关于'enum'枚举类型以及结构体的问题。
带您遨游太空,美摄科技为航天创意小程序提供全面技术支持
EMMC/SD学习小记
excel实战应用案例100讲(八)-Excel的报表连接功能
Detailed explanation of unwind stack backtracking
《Multi-modal Visual Tracking:Review and Experimental Comparison》翻译
在项目中的定时作用
Intelligent communication solution of Hainan Phoenix Airport
可视化之路(十)分割画布函数详解
Flexible blind patch of ad hoc network | Beifeng oil and gas field survey solution
美摄助力百度“度咔剪辑”,让知识创作更容易
Patrol inspection intercom communication system in power industry