6 ways in which JavaScript inherits

Source: Internet
Author: User

1. Prototype chain

Using prototypes to let one reference type inherit the properties and methods of another reference class

Each constructor has a prototype object, and the prototype object contains a pointer to the constructor, and the instance contains an internal pointer to the prototype object.

Example:

2. Borrowing constructors

The superclass constructor is called inside the subtype constructor, and the constructor can be executed on the innovative object through the call () and the Apply () method

Example:

3. Combining inheritance

Combine the prototype chain and the technique of borrowing the constructor together to play the two-way inheritance pattern of Yi

Example:

4. prototype-Type Inheritance

Prototypes can be used to innovate objects based on existing objects without having to create custom types

Example:

5. Parasitic inheritance

Create a function that encapsulates the inheritance process, which internally enhances the object in some way, and then returns the object as if it did all the work.

Example

6. Parasitic combined inheritance

Inheriting attributes by borrowing functions, inheriting them through the compositing form of the prototype chain

6 ways in which JavaScript inherits

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.