javaScript复习8
关于this
JavaScript中this一直是比较奇怪的,并不像java那样静态绑定当前对象。
那JavaScript的this到底是怎么定义的呢?
定义
The this keyword evaluates to the value of the ThisBinding of the current execution context. The this value depends on the callerand the type of code being executed and is determined when control enters the execution context. Thethis value associated with an execution context is immutable. (ECMA-3)
也就是说this是可执行代码类型有关系,在进入执行上下文时确定,而且不可改变。
read moreJavaScript复习7
执行上下文和变量对象 复习
执行上下文
每次当控制器转到ECMAScript可执行代码的时候,即会进入到一个执行上下文。活动的执行上下文组在逻辑上组成一个堆栈。堆栈底部永远都是全局上下文(global context),而顶部就是当前(活动的)执行上下文。堆栈在EC类型进入和退出上下文的时候被修改(推入或弹出)。
可执行代码类型
假设,可执行上下文堆栈是一个数组:
ECStack = [];
每次进入function或eval的时候,这个堆栈会被压入。
read more