Variable object

The execution context of the life cycle:
creation phase: create variable objects, the establishment of the scope chain, as well as to determine the point of this.
Code execution phases: variable assignment, function references, as well as execute other code.

The process of creating variable objects:
the establishment of the arguments object. Check the current context parameters, attributes and attribute values established in the object.
Check the function declaration for the current context, that is, use the function keyword to declare the function. Property to establish the function name, property value points to reference the function where the memory address. If the property function name already exists, then the property will be covered by a new reference.
Check the variable declaration in the current context, each find a variable declaration on the establishment of a property to the variable name in the variable object, the property value is undefined. If the variable name attribute already exists, in order to prevent the function of the same name is modified to undefined, it will skip the original attribute values are not modified.

testEC = {
    // 变量对象
    VO: {},
    scopeChain: {}
}

// VO 为 Variable Object的缩写,即变量对象
VO = {
    arguments: {...},  //注:在浏览器的展示中,函数的参数可能并不是放在arguments对象中,这里为了方便理解,我做了这样的处理
    foo: <foo reference>  // 表示foo的地址引用
    a: undefined
}

Variable objects and active objects What is the difference, they are actually the same object, but in the context of the implementation of the different life cycle. But only in the context of the implementation of variable object function call stack in the top of the stack, it will become active object.

// demo2
function test() {
    console.log(foo);
    console.log(bar);

    var foo = 'Hello';
    console.log(foo);
    var bar = function () {
        return 'world';
    }

    function foo() {
        return 'hello';
    }
}

test();

// 创建阶段
VO = {
    arguments: {...},
    foo: <foo reference>,
    bar: undefined
}
// 这里有一个需要注意的地方,因为var声明的变量当遇到同名的属性时,会跳过而不会覆盖

// 执行阶段
VO -> AO
VO = {
    arguments: {...},
    foo: 'Hello',
    bar: <bar reference>,
    this: Window
}

The global context has a special place, it's variable object is the window object

Author: This wave can kill instead
link: https://www.jianshu.com/p/330b1505e41d
Source: Jane book
Jane book copyright reserved by the authors, are reproduced in any form, please contact the author to obtain authorization and indicate the source.

Guess you like

Origin www.cnblogs.com/bingery/p/11331403.html