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:
- Factory mode: Simple function to create reference type
- 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.
- 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.
- Prototype inheritance: Creates objects based on objects, performing a shallow copy of a given type.
- Parasitic inheritance: objects are created based on objects and then internally enhanced.
- 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