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.