JS execution context to understand

Code Classification

First, we will JS code into global code and the function code, the global scope is global code to write code, globally valid code, the function code is written in the body of the function code is only valid function of body weight

Execution Context

Global execution context : the JS pre-parsed code prior to execution of the global data preprocessing, divided into the following three steps:
1, the defined global variables var add global object attributes, and assigning undefined;
2, function declared global function, add methods for the global object, assign function (that is the way to enhance the overall function of global variables);
3, assign this to the global object (the browser environment is the window object, Node.JS environment global object);
4, global code begins execution;
function execution context : before calling this function, the body is ready to execute the function, creates a corresponding function execution context object, to preprocess the data locally:
1, a function of the parameter variables (arguments ) was added to perform a context attribute;
2, local variables vivo var declaration add execution context attribute assignment undefined;
. 3, function function declaration added as a method execution context, the assignment function;
the this pointing object function call;
4, began to perform the function body codes;
Tips: In fact, variables L and enhance the function is to use execution context to explain.

Published 19 original articles · won praise 0 · Views 278

Guess you like

Origin blog.csdn.net/Joey_Tribiani/article/details/103758163