每个函数被定义时都会产生一个作用域,在浏览器内核里被命名为[scope],但是用户无法访问,其作用是用来存储运行期上下文的集合。
作用域链是指在函数定义或者运行时,多个作用域叠加在一起的集合,具体看下面个例子
function a (){
function b (){
function c(){
}
c();
}
b();
}
a();
当a被定义----->scope: GO{}
当a被执行----->scope: aAO{} GO{}
当b被定义----->scope: aAO{} GO{}
当b被执行----->scope: bAO{} aAO{} GO{}
当c被定义----->scope: bAO{} aAO{} GO{}
当c被执行----->scope: cAO{} bAO{} aAO{} GO{}
当c执行完----->scope: bAO{} aAO{} GO{}
以此类推