执行上下文:
/**执行上下文:
* 全局执行上下文:
* 执行全局代码前将window确定为执行上下文
* 全局数据预处理(变量提升和函数提升)
* 全局变量添加为window的属性
* 全局函数添加为window的方法
* this -> window
* 函数执行上下文:
* 执行函数体前,将函数确定为执行上下文
* 实参赋值给形参,添加为执行上下文的属性
* 实参列表 => arguments,添加为执行上下文的属性
* 声明的局部变量添加为执行上下文的属性
* 函数内声明的函数添加为执行上下文的方法
* this -> 调用函数的对象
*/
/**
* 全局执行上下文
*/
var num = 1;
function func() {
alert("hello");
}
console.log(num);
func();
/**
* 函数执行上下文
*/
function fun(para) {
var result = para + 1;
console.log(result);
function f() {
alert("run f");
}
f();
}
fun(); //函数执行前才创建函数执行上下文
执行上下文栈:
/**执行上下文栈:
* JS引擎使用栈来存储执行上下文对象
* 先将全局执行上下文window压栈,window始终位于栈底
* 函数执行上下文创建后,将其压栈
* 函数执行完毕后,将该函数执行上下文出栈,释放其对应的内存空间
*/