JS Implementation inheritance

Source: Internet
Author: User

1. Using an object to impersonate the inheritance (this implementation can implement multiple inheritance)
Implementation principle: Make the constructor of the parent class A method of the subclass, then call the method of the subclass, assign the value to all the properties and methods through the This keyword

2. Use call or Apply method to change function context to implement inheritance
Implementation principle: Change the function context inside the function this so that it points to the specific object passed into the function

3, the use of prototype chain to achieve inheritance
Implementation principle: The subclass prototype object points to the parent class to implement inheritance, that is, rewrite the prototype of the class, the disadvantage is not directly implement multiple inheritance

4, the use of hybrid mode to achieve inheritance

JS Implementation inheritance

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.