The process of JavaScript function execution

Source: Internet
Author: User
  1. Each of the JavaScript functions 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 collection of scopes called "Scope Chains", which store "variable object" VO or "active object" AO (ao ratio vo more this and arguments attributes) in the collection.

  2. When a function is created, all mutable objects in the scope chain of its parent scope are added to its [[scope]] (if the parent scope is global, 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 the variable initialization phase of the function is entered, and this stage determines the function's interior: This value, the function's arguments, the function's declaration, the Declaration of the variable, and the arguments. The active object AO, which makes up the current function according to these values, then saves the AO object to the first of the current function's scope chain.
      Note: The AO is populated in the following order:

      1. function parameters (if there is a parameter, it will be assigned, if the parameter is not passed, the initialization value is undefined) priority second
      2. function declaration (overrides if a naming conflict occurs) highest priority
      3. Variable declaration (the initialization variable value is undefined, if a naming conflict occurs, it is ignored) priority third
    2. Then, at the execution stage of the function, all the variables and function declarations used in this stage of the current function are looked up from the [scope] scope chain of the current function, and based on the position of the object in the scope chain, the AO object of the current function is first found, and if no further upper object is searched, the global object is If none, the error will be (the variable is undefined).

The first time to write a microblog, there are wrong or missing place also please correct me.

The process of JavaScript function execution

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.