Explanation of Javascript objects

Source: Internet
Author: User

All constructors are objects, and not all objects are constructors. Each constructor has a Prototype attribute used to implement Prototype inheritance and share attributes. An object is created using A new expression. For example, A new String ("A String") creates A String object. Directly calling the constructor without using new will return values, and the type returned will depend on the constructor. For example, String ("A String") generates A String of the original type rather than an object.
ECMAScript supports prototype-based inheritance. Each constructor has a prototype associated with it, and the objects created through this constructor have an implicit reference (called the object prototype) associated with the constructor prototype ). Further, a prototype may have a non-empty implicit reference to its prototype ......, This is called prototype chain. When a reference points to an object attribute, this reference points to the attribute of the first object in the prototype chain in this name. In other words, for the first time, the directly associated object will be checked for this attribute. If this object contains an attribute in the name of this object, this attribute is the attribute pointed to by the reference. If this object does not contain attributes in this name, the prototype of this object will be checked ......
Original article:
Object
ECMAScript does not contain proper classes such as those in C ++, Smalltalk, or Java, but rather, supports constructors which create objects by executing code that allocates storage for the objects and initialises all or part of them by assigning initial values to their properties. all constructors are objects, but not all objects are constructors. each constructor has a Prototype property that is used to implement prototype-based inheritance and shared properties. objects are created by using constructors in new expressions; for example, new String ("A String") creates a new String object. invoking a constructor without using new has consequences that depend on the constructor. for example, String ("A String") produces a primitive string, not an object.
ECMAScript supports prototype-based inheritance. every constructor has an associated prototype, and every object created by that constructor has an implicit reference to the prototype (called the object's prototype) associated with its constructor. furthermore, a prototype may have a non-null implicit reference to its prototype, and so on; this is called the prototype chain. when a reference is made to a property in an object, that reference is to the property of that name in the first object in the prototype chain that contains a property of that name. in other words, first the object mentioned directly is examined for such a property; if that object contains the named property, that is the property to which the reference refers; if that object does not contain the named property, the prototype for that object is examined next; and so on.

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.