JavaScript Advanced Programming Notes (IV)

Source: Internet
Author: User

First, basic type and value of reference type

Value of a reference type: An object that may consist of multiple values.

For values of reference types, we can add, change, and delete properties and methods.

var New Object ();         " Nicholas " ;        alert (person.name);     // "Nicholas"

But we can't add attributes to the base type.

Obj1 and Obj2 both point to the same object, and when you add the Name property to Obj1, you can access the property through Obj2 because the references to both properties are the same object.

var New Objcect (); var obj2 ="Nima"; alert (obj2.name);     // Nima

3. Passing parameters

Parameters can only be passed by value, and the passed value is copied to the local variable when the base type is passed to the parameter

        function Addten (num) {            num + =ten            ; return num;        }                 var result =////30

Even though the value of the parameter is modified inside the function, the original reference does not change. When you actually rewrite obj inside a function, the reference to that variable is a local variable.

4. Test Type

instanceof Operator: detecting reference Types

Syntax: variable instanceof cunstructor

instanceof // is the variable person an object?

The value of all reference types is an instance of object, and the detection reference type always returns true; the detection base type always returns False

II. implementation Environment and scope

1. Execution Environment: The execution environment is the most important concept in JS, which defines the other data that variables and functions have access to;

2. Variable object: Each execution environment has a variable object associated with it, and all variables and functions defined in the environment are stored in this object;

3. Global execution Environment: one of the outermost execution environments, depending on the host environment in which the ECMAScript implementation resides, the global execution environment is considered a Window object in a Web browser;

4. Destruction of the execution environment: after all code in an execution environment is executed, the environment is destroyed, which means that all of the variables and function definitions are destroyed; the destruction of the global execution environment is performed when the Web page or browser is closed;

5. Execution flow: Each function has its own execution environment, when the execution flow enters a function, the environment of the function is pushed into an environment stack, and when the function is executed, the stack will eject its environment and return control to the previous execution environment;

6. Scope Chain: When the code is executed in the environment, a chain of variables is created, and the role of the scope chain is to ensure an orderly access to all variables and functions that the execution environment has access to;

7. Front-end of the scope chain: Always a Variable object in the context of the current execution code, or its active object as a variable object if the environment is a function.

8. Backend of the scope chain: The variable object of the global execution environment is always the last object in the scope chain;

9. Analysis of identifiers (variables, functions, parameters): The search process is done at the level of the scope chain, and the search process is always started from the front end of the scope chain and goes backwards until the identifier is found; search for the last environment is not found,

will cause errors to occur;

Third, garbage collection

JavaScript Advanced Programming Notes (IV)

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.