The process of executing JavaScript functions _javascript techniques

Source: Internet
Author: User

1. each JavaScript function is an instance of a function object that has an internal property that is accessible only to the JavaScript engine [[Scope]]. This [[Scope]] stores a set of scopes called the "Scope Chain", which stores "variable object" VO or "active object" AO (ao more than VO this and arguments attributes).

2. When a function is created, all the mutable objects in the scope chain of its parent scope are 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 the function is executed, the execution environment of the function is pushed into an environment stack:

1. At this point, enter the function's variable initialization phase, which determines the internal function: This value, the function's arguments, the function's declaration, the variable's declaration, and the arguments. The active object AO, which makes up the current function based on these values, then saves the AO object to the top of the current function scope chain.

Note: AO fills in the following order:

1. Function parameters (if there are arguments, will be assigned, if not the parameters, initialization value of undefined) priority of the second
2. function declaration (overwrite if a naming conflict occurs) highest priority
3. Variable declaration (initialization variable value is undefined, if a naming conflict occurs, ignore) priority third
2. Then it's time to go to the function's execution stage, all variables and function declarations that are used in the current function in this phase are found from the scope chain of the current function, and the AO object of the current function is first looked up according to the position of the object in the scope chain, and if the upper object is not searched, the global object is finally located. If none, the error is not defined (the variable is undefined).

This JavaScript function is the implementation of the process is small to share all the content of everyone, hope to give you a reference, but also hope that we support the cloud-dwelling community.

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.