InheritanceES5 prototype inheritance Inheritance is achieved through the prototype chain (constructor + [[prototype]]). (Note: I will write __proto__ in the form of [[prototype]] in the future) // Parent class: function SuperType; Subclass: function SubType; SubType.prototype = new SuperType(); // SubType inherits SuperType // According to the knowledge point mentioned in the previous section on prototype chain: the __proto__ of the instantiated object is equal to the prototype of the constructor SubType.prototype.__proto__ === SuperType.prototype // true The inheritance relationship above is as follows: In terms of internal implementation mechanism, the inheritance of ES5 is actually to first create an instance object of the subclass on this, and then add the parent class method to this this. Similar usage: Father.apply(this) ES6 class inheritance Inheritance is achieved through class's extends + super. Super usage super can be used as a function and an object. The difference between the twoA: They are not exactly the same. There are several main differences:
ES5 prototype inheritance internal implementationInheritance in ES5 is essentially creating an instance object of the subclass this first, and then adding the parent class's method to the subclass (this) --- Father.apply(this). ES6 class inheritance internal implementationThe inheritance mechanism of ES6 is completely different. In essence, it first creates an instance object this of the parent class, puts the properties and methods of the parent class on this (provided that it is called through the super function), and then uses the constructor of the child class to modify this. Because of the different implementation mechanisms, these two types of inheritance have some differences when inheriting native constructors: es5 writing cannot inherit native constructors (such as Array, Number, etc.) ExtensionsFor a description of the internal implementation mechanism, please refer to the relevant section of "Ruan Yifeng's es6 Document - Class Inheritance" This concludes this article about the differences between ES6 inheritance and ES5 inheritance in Java. For more information about the differences between ES6 inheritance and ES5 inheritance, please search 123WORDPRESS.COM’s previous articles or continue browsing the following related articles. I hope you will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: A Brief Analysis of Subqueries and Advanced Applications in MySql Database
>>: Implementation of grayscale release with Nginx and Lua
vmware workstations starts the virtual machine er...
Before further analyzing why MySQL database index...
SQL method for calculating timestamp difference O...
In Docker Start all container commands docker sta...
Declaring variables Setting Global Variables set ...
Table of contents Identifier length limit Length ...
FOUC is Flash of Unstyled Content, abbreviated as ...
Table of contents 1. Timer monitoring 2. Event mo...
This article shares the specific code for JavaScr...
Table of contents 1. How to monitor Tomcat 2. Jav...
Table of contents 1. First, configure the main.js...
Q1: What indexes does the database have? What are...
Allow './' relative paths in docker-compo...
Table of contents introduce Link start Continue t...
Many people now live on the Internet, and searchin...