Home > Web Front-end > JS Tutorial > body text

Execution process of JavaScript function_javascript skills

WBOY
Release: 2016-05-16 09:00:21
Original
1814 people have browsed it

1. Each JavaScript function is an instance of the Function object, which has a function that is only accessible to the JavaScript engine. The internal attribute [[Scope]]. This [[Scope]] stores a collection of scopes. This collection is called the "scope chain". The collection stores "variable objects" VO or "active objects" AO( AO has more this and arguments attributes than VO).

2. When a function is created, all mutable objects in the scope chain of its parent scope will be added to its [[scope]] (if the parent scope is global, then only one global object will be added to the scope chain of the current function).

3. When a function is executed, the execution environment of the function will be pushed into an environment stack: p>

1. At this time, we enter the variable initialization phase of the function. This phase will determine the internals of the function: this value, function parameters, function declaration, variable declaration, and arguments. Based on these values, the active object AO of the current function is formed. The AO object will then be saved to the top of the current function scope chain.

Note: AO is filled in the following order:

1. Function parameters (if there are parameters passed, they will be assigned values, if no parameters are passed, the initial value is undefined), the second priority
2. Function declaration (if a naming conflict occurs, it will be overwritten) has the highest priority
3. Variable declaration (initialize the variable value to undefined, if a naming conflict occurs, it will be ignored) Third priority
2. Then comes the execution stage of the function. At this stage, all variables and function declarations used in the current function will be searched from the [[Scope]] scope chain of the current function. According to the position of the object in the scope chain, they will first be searched. If the AO object of the current function does not search for the upper-level object, it will finally find the global object. If there is none, an error will be reported (the variable is undefined).

The execution process of the above JavaScript function is all the content shared by the editor. I hope it can give you a reference, and I also hope you will support Script Home.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!