Comments (2)
什么是执行上下文?
简而言之,执行上下文是评估和执行 JavaScript 代码的环境的抽象概念。每当 Javascript 代码在运行的时候,它都是在执行上下文中运行。
执行上下文的类型
JavaScript 中有三种执行上下文类型。
全局执行上下文
。这是默认或者说基础的上下文,任何不在函数内部的代码都在全局上下文中。它会执行两件事:创建一个全局的window
对象(浏览器的情况下),并且设置this
的值等于这个全局对象。一个程序中只会有一个全局执行上下文。函数执行上下文
。每当一个函数被调用时, 都会为该函数创建一个新的上下文。每个函数都有它自己的执行上下文,不过是在函数被调用时创建的。Eval
函数执行上下文 。执行在eval
函数内部的代码也会有它属于自己的执行上下文。
执行栈
执行栈,也就是在其它编程语言中所说的“调用栈”,是一种拥有 LIFO
(后进先出)数据结构的栈,被用来存储代码运行时创建的所有执行上下文。
当 JavaScript
引擎第一次遇到你的脚本时,它会创建一个全局的执行上下文并且压入当前执行栈。每当引擎遇到一个函数调用,它会为该函数创建一个新的执行上下文并压入栈的顶部。
引擎会执行那些执行上下文位于栈顶的函数。当该函数执行结束时,执行上下文从栈中弹出,控制流程到达当前栈中的下一个上下文。
from fe_interview.
关于执行栈(也就是调用栈)还有一点要注意的是,调用栈是有大小的,当入栈的执行上下文超过一定数目,JavaScript
引擎就会报错,我们把这种错误叫做栈溢出(Stack Overflow
)。
from fe_interview.
Related Issues (20)
- Vue中v-html会导致哪些问题?
- 如何理解MVVM原理?
- 为什么Vue采用异步渲染? HOT 1
- Vue父子组件生命周期的调用顺序?
- Vue中v-model的实现原理以及如何自定义v-model
- 谈谈你对keep-alive的理解 HOT 2
- 你知道Vue中的computed是怎么实现的吗? HOT 1
- Vue ajax请求放在哪个生命周期中? HOT 2
- 说一下js中的词法作用域和动态作用域 HOT 2
- var缺陷以及为什么要引入let和const?
- 谈一下js中的作用域链 HOT 1
- 手写一个符合Promises/A+规范的promise HOT 1
- 说一下几种常见算法的时间复杂度 HOT 1
- 说一下浏览器缓存
- es module和commonjs的区别
- for、forEach、map的性能对比
- Webpack热更新的原理
- 简单说下webpack中的文件指纹策略 HOT 1
- 讲一下TCP三次握手、四次挥手过程及原理 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fe_interview.