Prototyping and closure focus

Source: Internet
Author: User

1, (Undefined, number, String, Boolean) belongs to a simple value type, not an object. Functions, arrays, objects, NULL, new number (10) are all objects. They are all reference types. It is very simple to judge whether a variable is not an object. The type of the value type is judged with typeof, and the type of the reference type is judged with instanceof.

2. All (reference types) are objects, and objects are collections of properties . objects are created through functions.

3, each function functions have a prototype, that is, the prototype. Add one more sentence here-each object has a __proto__ that can become an implicit prototype. Each object has a __proto__ property that points to the prototype of the function that created the object. Object.prototype is really a special case-its __proto__ point is null, remember to remember!

4, to access the properties of an object, first look in the basic properties, if not, and then follow the chain up __proto__, this is the prototype chain.

5, variable, function expression--variable declaration, the default assignment is undefined;this--assignment, function declaration--assignment, the preparation of these three kinds of data we call "execution context" or "execution context". Each time a function is called, a new execution context is generated. When the function is defined (not when it is called), the scope of the free variable inside the function body is determined.

5. The value of this in the function is determined when the function is actually called and the function definition is not. If the function is a property of an object and is called as a property of an object, this point in the function points to the object. Note that if the FN function is not called as an attribute of obj, if the FN function is assigned to another variable and is not called as an attribute of obj, then the value of this is window,this.x to undefined. In fact, not only the prototype of the constructor, even in the entire prototype chain, this represents the value of the current object.

6. when executing the global code, an execution context is generated, and each invocation of the function results in an execution context. When the function call is complete, the context and the data in it are eliminated and then back to the global context. There is only one execution context environment that is active. In fact, this is a stack out of the process-the execution context stack.

7, to create this function in the scope of the value-is "create", rather than "call", remember to remember-in fact, this is called "Static scope." This step-by-step "cross" route, as we call it, is a chain of scopes.

8, but you only need to know the application of two cases--function as the return value, the function as a parameter passed. In some cases, after a function call is complete, its execution context is not subsequently destroyed. This is what is needed to understand the core of closures.

Prototyping and closure focus

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.