Javascript closure notes

Source: Internet
Author: User

1. Closure Definition

Internal functions are allowed-that is, function definitions and function expressions are located in the function body of another function. In addition, these internal functions can access all the local variables, parameters, and other declared internal functions declared in their external functions. When one of these internal functions is called outside the external functions that contain them, a closure is formed.

2. Background Knowledge

Object

Ecmascript recognizes two types of objects

Native object-language

Host Object-provided by the Environment

Create attributes

You can dynamically and loosely add attributes to an object.

VaR OBJ = new object ();// Create a JavaScript Object

OBJ. testnumber = 5;// Create a new property named "testnumber", which is created only after being assigned a value.

Read attributes

VaR objectref = new object ();

Create a common JavaScript Object. The prototype of the object is the object. Prototype object, while the object. Prototype object has a prototype with a null value. This forms the so-called prototype chain. The prototype chain ends with an object whose original type is null.

When an attribute accessor attempts to read the attribute value of an object, the entire prototype chain is searched. If no object has this attribute, undefined is returned.

note: ecmascript defines an internal [[prototype] attribute for the object type. This attribute cannot be directly accessed through scripts, but the object chain referenced by this internal [prototype] attribute is required during the property accessors parsing process-the prototype chain. A common prototype attribute can be used to assign values or define prototype objects corresponding to the internal [[prototype] attribute. The relationship between the two is described in detail in ECMA 262 (3rd edition), but beyond the scope of this 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.