当前位置:网站首页>JS scope chain and closure
JS scope chain and closure
2022-07-01 09:18:00 【su27_ 0101】
On closures, let's talk about scope chains first
js Scope contains overall situation and function Scope (es5)
Such as :
var a = 'global var'
function fn(){
var b = 'function var';
var n = function(){
var c = 'inner function var'
}
}
c //; undefined
Use Venn's diagram to describe the current scope division 
Closures can be used to break through the scope chain
If you want to access the internal function in the global scope c Variable You need to use closures to connect it to the global scope
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'
Closure and GC
js gc use Reference count
In my submission Closures are used Reference count characteristic , bring Locally scoped variable references +1 Can't release
边栏推荐
猜你喜欢

Ranking list of domestic databases in February, 2022: oceanbase regained the "three consecutive increases", and gaussdb is expected to achieve the largest increase this month

Bird recognition app

【pytorch】softmax函数

How to launch circle of friends marketing and wechat group activities

Principle and application of single chip microcomputer timer, serial communication and interrupt system

2022.02.15_ Daily question leetcode six hundred and ninety

Ape anthropology topic 20 (the topic will be updated from time to time)

Which method is good for the management of fixed assets of small and medium-sized enterprises?

How to manage fixed assets well? Easy to point and move to provide intelligent solutions

Jetson Nano 安装TensorFlow GPU及问题解决
随机推荐
js 使用toString 区分Object、Array
【ESP 保姆级教程 预告】疯狂Node.js服务器篇 ——案例:ESP8266 + DHT11 +NodeJs本地服务+ MySQL数据库
dsPIC30F6014a LCD 方块显示
短路运算符惰性求值
[ESP nanny level tutorial preview] crazy node JS server - Case: esp8266 + DS18B20 temperature sensor +nodejs local service + MySQL database
Yidian Yidong helps enterprises to efficiently manage equipment and improve equipment utilization
Flink interview questions
How to launch circle of friends marketing and wechat group activities
Niuke monthly race 22 tree sub chain
Nacos service configuration and persistence configuration
How to realize the usage of connecting multiple databases in idel
2.2 【pytorch】torchvision. transforms
Mise en œuvre simple de l'équilibrage de la charge par nacos
Ape anthropology topic 20 (the topic will be updated from time to time)
LogBack
[pytorch] softmax function
小鸟识别APP
How to manage fixed assets efficiently in one stop?
The fixed assets management system enables enterprises to dynamically master assets
树结构---二叉树2非递归遍历