This is the 13th day of my participation in the August More Text Challenge. For details, see:August is more challenging
Special festival, but also to continue to more text ah, I wish you a happy Chinese Valentine’s Day ohAs a mature programmer, new objects are every minute
Hello, everyone, I am circle, love the front end, like to share, thank you very much for this activity, I hope I can stick to it, thank you so beautiful, also read my article, welcome to comment area exchange and play ~
Javascript code runs in the browser
ECStack (Execute Context Stack)
Stack memory function
- Function 1: For code execution
- Function 2: Stores raw values and variables
EC(G)(Execution Context Global) Indicates the Global Execution Context
- Purpose: To distinguish the environment in which the code is executed
- Global code is executed in a global context
VO(G)(Variable Object Global) Global Variable Object
- Stores variables declared in the current context
- The memory in a computer, ram ROM
- Memory: Stack memory, Heap memory
- Running memory allocated on a memory bar [CPU]
- Front-end performance optimization: Memory optimization
The operation of equals = assignment
1. Create a value (original value & object)
- Raw value: find a place in the stack memory to store
- Object: a separate heap memory space; Used to store information such as members of an object
2. Declare a variable, store the declared variable in the current context “variable object VO/AO”
var/function/let/const/import….
3. Associate variables with Defined definitions
Object type [non-function] Assignment operation
- Create a heap memory space -> creates a common access address [hexadecimal]
- To store the key-value pairs in an object in space at once
- The spatial address is stored on the stack for reference to variables
Window global object
VO(G) Global variable object: Stores variables declared in a global context
Operator priority in JS developer.mozilla.org/zh-CN/docs/…
Read the underlying execution mechanism of the function in detail
Big factory interview questions know how much ~
1 / / thinking
var a = {n: 1}; //-> heap memory 0x000
var b = a;
a.x = a = { n:2}
console.log(a.x) //undefined
console.log(b) //
Copy the code
2 / / thinking
var x = [12.23];
function fn(y) {
y[0] = 100;
y = [100];
y[1] = 200;
console.log(y); / / [100200]
}
fn(x);
console.log(x); / / / 100,
Copy the code
Create function:
- Carve out a heap memory, with a hexadecimal address
- Stored content
- The code in the body of the function is stored as a string
- As a normal object, we also store some key and value pairs
- When you create a function, you declare its scope.
- The address of the heap memory is placed on the stack for the function name (variable) to call
Fn function execution -> execute the code string stored in the function body as code, fn(0x000) forms a new “private” execution context EC(fn) [stack execution]
An AO is also a variable Object. It is a subset of VO functions called AO, global VO, and block-level VO execution functions
1. Form a private execution context EC(…) , and then push it into the stack
AO(…)
What to do before the function executes
- Initialize the SCOPE chain scope-chan
(fn),ec(g)>
Left: own private context Right: function SCOPE
- Purpose: Later in the function context code execution, encountered variables, first to see if the private,
- If it is not private, then look for its parent context in the scope chain… (Scope chain mechanism)
- Initialize this to
- Initialize arguments[argument set]
- Parameter assignment [parameter is a private variable and will be stored in all variable objects of I]
7. Variable promotion 8. Code execution
The road ahead is long; I see no ending. I will search up and down
Welcome to leave a comment ~