We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
以这个例子说明下你对执行上下文的理解
var color = 'blue'; function changeColor() { var anotherColor = 'red'; function swapColors() { var tempColor = anotherColor; anotherColor = color; color = tempColor; } swapColors(); } changeColor();
The text was updated successfully, but these errors were encountered:
执行上下文包含,变量和作用域链,以这个例子来说 第一阶段是预编译创建变量 color, changeColor, anotherColor, swapColors, tempColor 包括变量提升 第二阶段是执行代码 包括变量的赋值,在函数调用时激活对应的作用域,才可以访问对应作用域中的变量,changeColor执行才可以访问anotherColor,swapColors执行才可以访问tempColor 第三阶段是销毁,当前作用域内函数调用完毕后就会将相关的变量销毁,这里涉及函数调用,是栈型结构,所以先调用的后出栈,swapColors调用后,swapColors出栈并将不再被引用的变量tempColor销毁,然后changeColor 出栈将不再被引用的anotherColor、swapColors 销毁。
color
changeColor
anotherColor
swapColors
tempColor
完事了
Sorry, something went wrong.
1第一阶段 预编译阶段,包括作用域的生成,内存分配,变量提升等var color changeColor 函数提升,函数内的代码提升,包括anotherColor,swapColors tempColor等 2.第二阶段代码执行,作用域链的生成,调用栈,例如上面的例子,全局上下文入栈,遇到可执行代码changeColor 入栈,遇到swapColors,入栈 3.销毁 swapColors 出栈,tempColor 销毁,changeColor 出栈anotherColor 销毁 color的销毁???
之前看标题以为是说this的(我的错),来公司早了,大概总结了一下this,回复打开发现主要是变量提升方面,上面两个讲的都很对,那我只能从this方面敷衍一下这道题了。https://catsaid.cn/2020/07/22/this/
说执行上下文除了作用域链,变量提升,this之外还有一个绕不开的话题:闭包。改天在弄吧~~先上班了
No branches or pull requests
以这个例子说明下你对执行上下文的理解
The text was updated successfully, but these errors were encountered: