In-depth analysis of JavaScript Object System-1. Object

Source: Internet
Author: User

@ Wu Qiong Adam (Sina Weibo)
In the process of learning JavaScript, it is often confused by its Object system (Object, Function, Prototype). If you do not understand these things, subsequent JavaScript learning will not be solid, so make up your mind to understand it. Let's get started!
 
During this learning process, The main bibliography is JavaScript: The Good Parts, JavaScript: The Definitive Guide, and Object-Oriented JavaScript: Create scalable, reusable high-quality JavaScript applications, and libraries; the main analysis tools are IE and IE Developer Tools.
 
 
 
1. Object
 
JavaScript language does not have the concept of classes. Except for basic types (Number, String, booleans, null, and undefined), everything is an object. The object definition is as follows, which is more accurate in English:
 
Objects are mutable keyed collections.
An object is a container of properties, where a property has a name and a value.
A property name can be any string, including the empty string.
A property value can be any JavaScript value before t for undefined.
These are not difficult to understand. The key is:
 
Object names des a prototype linkage feature that allows one object to inherit the properties of another.
Here, this prototype link is hidden (invisible in the Debugger). In some implementations, its attribute name is _ proto __
 
So far, the domain model after the JavaScript Object System is modeled using UML is as follows:
 
 
 
Additionally, the _ proto _ link of any Object is not empty. For an Object created from Object Literal, its _ proto _ points to Object. prototype.
 
 
 
With the _ proto _ link, you can exert some object-oriented power. The first one is Delegation. Delegation means that when an attribute fails to be obtained from an object, JS will automatically try to find it in the object indicated by its _ proto _ link. If it still cannot be found, follow _ proto _ to find the Object. prototype. According to the description of the preceding Delegation algorithm, you can easily understand that the Delegation process is dynamic. This time, you can find the attribute from the ancestor, which does not necessarily mean that you can find it next time.
 
 
 
Note that the __proto _ link is only valid for queries, but not for Update. That is to say, if you assign a value to an attribute, this property does not exist in this object, but the _ proto _ ancestor already has an attribute of the same name. However, JS will create another attribute in this object instead of modifying the attribute value of the ancestor.


From column adwu73

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.