JavaScript prototypes and prototype chains

Source: Internet
Author: User

I. The relationship between objects and functions

1. An object is a function creation, and a function is an object.

2. How objects are created

The 2.1.Object constructor creates an object, new objects ();

2.2. The literal creation of the object var x = new (), which is essentially created by the new object method.

2.3. Create from Factory mode, use new Object () in the method, you can create multiple objects.

2.4. Create an object using the constructor.

2.5. Create an object using a prototype.

2.6. Create an object using constructors and prototypes.

2.7 use Object.create (); Create object.

3. Functions, objects, prototypes, prototype chains

1. Each function has a prototype, and each object has a __proto__.

2.__proto__ (implicit prototypes) and prototype (explicit prototypes).

Implicit prototypes: Each function will have a property named prototype after it is created, which points to the prototype object of the function.

Display prototypes: Any object in JavaScript has a built-in property [[prototype]] and there is no standard way to access this built-in property before ES5, but most browsers support access through __proto__.

Relationships: Implicit prototypes point to Prototype (display prototypes) of functions that create this object (constructor)

Role: The role of explicit prototypes: used to implement prototype-based inheritance and attribute sharing, the role of implicit prototypes: forming a prototype chain, also used to implement prototype-based inheritance. For example, when we visit the X attribute in obj, if it is not found in obj, it will be searched along the __proto__.

JavaScript prototypes and prototype chains

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.