当前位置:网站首页>43.js -- scope chain
43.js -- scope chain
2022-07-28 02:58:00 【Like to drink pearl milk tea】
Tips : When the article is finished , Directories can be generated automatically , How to generate it, please refer to the help document on the right
List of articles
1. Scope chain concept
stay JavaScript in , Functions are also objects , actually ,JavaScript It's all about objects . Function objects are just like other objects , Has properties that can be accessed by code and a series of properties JavaScript Internal properties accessed by the engine .
[[scope]] A collection of runtime context objects stored in , This set is linked in a chain , We call this chain connection Scope chain of function , It determines which data can be accessed by functions .
The purpose of the scope chain is Ensure orderly access to all variables and functions that the execution environment has access to .
2. Execution context
When the function executes , An internal object called the execution context is created . An execution time context defines the environment in which a function executes , Each time a function executes, the corresponding execution context is unique , So calling a function multiple times can result in multiple execution contexts being created , When the function is finished executing , The execution context it generates is " The destruction ".
<pre> analysis 1: Execution context refers to the context generated immediately before the function is executed AO object </pre>
<pre> analysis 2: The function execution environment refers to those obtained by the variable promotion function AO Object properties </pre>
<pre> analysis 3:
function test() { }Function called many times , Produce different AO object :
test(); ---->AO{}
test(); ---->AO{}
After the function is executed, the corresponding AO Destruction of objects .
</pre>
[[scope]] It refers to what we call the scope , A collection in which the runtime context is stored .
js Object has two kinds of members
One is the above member (js Members whose syntax can be accessed directly )
One is the following members ( Members accessed by the underlying syntax )
[[scopes]] Enclosed member names Is the following member
function fn () { } console.dir(fn)This " object " What is saved internally is the scope of the function
The function is defining / When making a statement And then there is [[scopes]] The upper layer is preserved inside AO object
Function call will generate AO object AO Save in scopes Inside the object
for example :
function fn (b) { var a=20 function fm () { } } fn(100) fn(200)
When the function is generated, there will be an attribute [[scopes]] Scope " Array "( Engine only )
Generated when the function is called AO object Will be able to AO The object is placed in scopes
Each call will be placed in scopes front ( Top )
Each function scopes There is one in the array AO object It is the upper layer of this function AO
Case study 1:
function fn() { var a = 30 function fm() { var b = 20 console.log(a) } fm() fm() } fn() fn()Running results :
Case study 2:
function fn(a) { function fm() { var b = 20 console.log(a) } fm() fm() } fn(100) fn(200)Running results :
Program :
function a() { var aaa = 123; function b() { var bbb = 234; console.log(aaa); } return b; } var glob = 100; var demo = a(); demo();Running results :
Execution process :
Go:{a function ,glob:100,demo:a.[[scopes In the object ,b function ]]}
a.[[scopes]]==>[AO:{aaa:123,b function ,},Go]
b function .[[scopes]]==>[,a.[[scopes]]]<====>[AO(b):{bbb:234, Print aaa},AO(a):{aaa:123,b function ,},Go]
边栏推荐
- Docker高级篇-Docker容器内Redis集群配置
- 社恐适合什么工作?能做自媒体吗?
- @Valid的作用(级联校验)以及常用约束注解的解释说明
- 1313_ Pyserial installation and document generation
- 别再用 offset 和 limit 分页了,性能太差!
- JS 事件对象2 e.charcode字符码 e.keyCode键码 盒子上下左右移动
- 没法预测明天的涨跌
- How do gateways and chirpstacks in lorawan communicate? UDP? GRPC? MQTT?
- 欢迎使用CSDN-markdown编辑器阿萨德
- JS event object offsetx/y clientx y pagex y
猜你喜欢

Four methods of modifying MySQL password (suitable for beginners)

Hardware standard

TFX airflow experience

【信号处理】基于高阶统计量特征的通信系统中微弱信号检测附matlab代码

tfx airflow 使用体验

Is it you who are not suitable for learning programming?

Chapter III queue

Newline required at end of file but not found.

入职华为od一个月的感受

IO flow: node flow and processing flow are summarized in detail.
随机推荐
Share an esp32 relay
Redis aof日志持久化
【TA-霜狼_may-《百人计划》】图形3.7 移动端TP(D)R架构
【stream】并行流与顺序流
TypeScript(零) —— 简介、环境搭建、第一个实例
clientY vs pageY
openGauss源代码,用什么IDE工具管理、编辑、调试?
NPDP考生!7月31号考试要求在这里看!
Explanation of CNN circular training | pytorch series (XXII)
First knowledge of C language -- operators and keywords, define, pointer
Opengauss source code, what ide tools are used to manage, edit and debug?
Eigenvalues and eigenvectors
Constant power wireless charging based on stm32
Digital twin agriculture - Smart agriculture rice processing plant has changed from "watching the sky to eat" to "knowing the sky to work"
PS simple to use
【ELM分类】基于核极限学习机和极限学习机实现UCI数据集分类附matlab代码
注意,这些地区不能参加7月NPDP考试
D multi production single consumption
新基建助力智能化道路交通领域的转型发展
Confusion matrix in CNN | pytorch series (XXIII)


