JavaScript function Execution Process _ javascript skills

Source: Internet
Author: User
The following small series will bring you a JavaScript function execution process. I think it is quite good. Now I will share it with you and give you a reference. Let's take a look at it with xiaobian. 1.Every JavaScript Function is an instance of a Function object. It has an internal attribute [Scope] That is only accessible to the JavaScript engine. this [Scope] stores a set of scopes. This set is called "Scope chain ", the Set stores "mutable object" VO or "active object" AO (which has more this and arguments attributes than VO ).

2.After a function is created, all the variable 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 is added to the scope chain of the current function ).

3.When a function is executed, the execution environment of the function is pushed into an environment Stack:

1. at this point, enter the variable initialization stage of the function. At this stage, the internal function will be determined: this value, function parameters, function declaration, variable declaration, and arguments. according to these values to form the active object AO of the current function, the AO object will be saved to the first part of the current function scope chain.

Note: Fill the AO in the following order:

1. function parameters (if any parameter is passed, it will be assigned a value. If no parameter is passed, the initial value is undefined.) Priority 2
2. function declaration (if a name conflict occurs, it will overwrite it) with the highest priority
3. Variable Declaration (the initialization variable value is undefined. If a name conflict occurs, it will be ignored) Priority 3
2. then, the function execution phase is reached. All variables and function declarations used in the current function in this phase will be searched from the [[Scope] Scope chain of the current function, first, the AO object of the current function will be searched based on the location of objects in the scope chain. If no upper-level objects are found, the system will return an error (the variable is undefined ).

The execution process of the above JavaScript function is all the content that I have shared with you. I hope you can give me a reference and support me a lot.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.