变量位置
let、const声明的全局变量绑定在Script对象上,var声明的全局变量在Global对象上,var、let、const声明的局部变量在Local对象上。注:Global、Script、Local是并列关系。
执行上下文
- this 绑定
- 词法环境(LexicalEnvironment)
- 变量环境(VariableEnvironment)
注意:执行上下文中的词法环境、变量环境并没有包含关系,outer 的引用在定义的时候就确定了
// 全局执行上下文
GlobalExectionContext = {
// 确定this
ThisBinding: <Global Object>,
// 词法环境
LexicalEnvironment: {
// 环境记录
EnvironmentRecord: {
Type: "Object", // 全局环境
},
outer: <null> // 对外部环境的引用
},
// 变量环境
VariableEnvironment = { ... },
}
// 函数执行上下文
FunctionExectionContext = {
ThisBinding: <Global Object>,
LexicalEnvironment: {
EnvironmentRecord: {
Type: "Declarative",
Arguments: {}
},
outer: <Global or outer function environment reference>
}
}