JavaScript advanced Programming-Object-oriented summary

Source: Internet
Author: User

ECMAScript supports object-oriented programming where objects can be created at code execution time, with dynamic extensibility rather than strictly physical entities .

To create an object method:

  1. Factory mode: Simple function to create reference type
  2. Constructor mode: You can create custom reference types, you can create built-in objects by using the new operator, constructors cannot be reused, and functions cannot be shared.
  3. Prototype mode: Use the constructor's prototype property to specify shared properties and methods, use constructors to define instance properties, and prototype patterns to share methods when combining constructors and prototype patterns.

JavaScript implements inheritance primarily through the prototype chain, assigning an instance of one type to another prototype object implementation inheritance. This way the class can access the methods and properties of the superclass. To note that the prototype chain shares all inherited properties and methods , the reference type comes first, and the workaround is implemented by borrowing the constructor, which calls the parent class's constructor implementation within the subclass constructor to inherit the parent class's properties, using the most common method is the combined inheritance, through the prototype inheritance method, Inherits instance properties through constructors.

  1. Prototype inheritance: Creates objects based on objects, performing a shallow copy of a given type.
  2. Parasitic inheritance: objects are created based on objects and then internally enhanced.
  3. Parasitic combination inheritance: Parasitic inheritance and combination inheritance of the advantages of the collection, the implementation of an effective method of inheritance.

JavaScript advanced Programming-Object-oriented summary

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.