当前位置:网站首页>js作用域链与闭包
js作用域链与闭包
2022-07-01 09:13:00 【su27_0101】
谈闭包先谈作用域链
js作用域包含 全局 和 函数 作用域(es5)
如:
var a = 'global var'
function fn(){
var b = 'function var';
var n = function(){
var c = 'inner function var'
}
}
c //; undefined
使用文氏图描述当前作用域划分
闭包可用于突破作用域链
如果要在全局作用域访问内部函数的c变量 需要使用闭包将其与全局作用域相连
var a = 'global var'
function fn(){
var b = 'function var';
var n = function(){
var c = 'inner function var'
return c;
}
return n();
}
c = fn();
c;// 'inner function var'
闭包与GC
js gc 采用 引用计数
我认为 闭包就是利用了 引用计数 特点,使得 局部作用域的变量引用+1 无法释放
边栏推荐
- Installing Oracle EE
- NiO zero copy
- An overview of the design of royalties and service fees of mainstream NFT market platforms
- Football and basketball game score live broadcast platform source code /app development and construction project
- 如何高效拉齐团队认知
- Mysql8.0 learning record 17 -create table
- Jetson nano installs tensorflow GPU and problem solving
- Installation and use of NoSQL database
- The jar package embedded with SQLite database is deployed by changing directories on the same machine, and the newly added database records are gone
- Preparing for the Blue Bridge Cup -- bit operation
猜你喜欢

Pain points and solutions of fixed assets management of group companies

I use flask to write the website "one"

Pain points and solutions of equipment management in large factories

Simple load balancing with Nacos

Daily practice of C language - day 80: currency change

How to solve the problem of fixed assets management and inventory?

An overview of the design of royalties and service fees of mainstream NFT market platforms

Nacos service configuration and persistence configuration
![2.3 [kaggle dataset - dog feed example] data preprocessing, rewriting dataset, dataloader reading data](/img/6e/d8ef618127ac492f5142f7b600266d.png)
2.3 [kaggle dataset - dog feed example] data preprocessing, rewriting dataset, dataloader reading data

樹結構---二叉樹2非遞歸遍曆
随机推荐
【pytorch】nn. Crossentropyloss() and nn NLLLoss()
2.3 【pytorch】数据预处理 torchvision.datasets.ImageFolder
Promise asynchronous programming
Serialization, listening, custom annotation
FAQ | FAQ for building applications for large screen devices
How to launch circle of friends marketing and wechat group activities
[ESP nanny level tutorial preview] crazy node JS server - Case: esp8266 + DS18B20 temperature sensor +nodejs local service + MySQL database
【pytorch】nn.CrossEntropyLoss() 与 nn.NLLLoss()
pcl_viewer命令
Latex插入的eps图片模糊解决方法
【ESP 保姆级教程】疯狂毕设篇 —— 案例:基于阿里云和Arduino的化学环境系统检测,支持钉钉机器人告警
[pytorch learning] torch device
Shell script - special variables: shell $, $*, [email protected], $$$
【pytorch】nn.AdaptiveMaxPool2d
Shell脚本-while循环详解
Which method is good for the management of fixed assets of small and medium-sized enterprises?
Log4j log framework
Shell script -select in loop
Microcomputer principle - bus and its formation
微信小程序 webview 禁止页面滚动,同时又不影响业务内overflow的滚动的实现方式