ES5 constructor syntax and ES6 constructor class

  First, we need to know that both the ES5 constructor syntax and the ES6 constructor class are syntax created for constructors, so we need to understand

Definition of constructor: a function dedicated to generating the data type of an object, its essence is also a function. The constructor is divided into: 1.JavaScript

The constructor defined by the program is called the built-in constructor; 2. The constructor defined in the project is called the custom constructor.

  The difference between the constructor and the ordinary function: 1. The constructor must be used with the keyword new; 2. The grammar specifies the function name of the constructor

The first letter must be capitalized, using the big camel nomenclature; 3. The syntax used to define properties and methods for instantiated objects is different from general functions.

  ES5 constructor syntax:

  

  ES6 constructor syntax: The comparison between ES6 and ES5 constructor syntax has the same function but the syntax is different.

  Difference: ES6 adds 1.class class, which is used to define keywords of attributes and attribute values; 2.constructor, define instantiation in the constructor

The attributes and attribute values ​​of the object are exactly the same as the ES5 syntax, except that the writing format position is different.

  In particular, the class class defined by ES6 syntax cannot be called in advance and cannot perform pre-parse; the function function of ES5 can be called in advance, but only the attributes do not

method.

Guess you like

Origin www.cnblogs.com/zhanglei154636/p/12724147.html