Home >Web Front-end >Front-end Q&A >Can es6 and es5 be mixed?

Can es6 and es5 be mixed?

WBOY
WBOYOriginal
2022-08-18 16:34:501497browse

es6 and es5 can be mixed and used; ECMAScript upgrades are as compatible as possible with all previous versions, that is, es6 contains the syntax of all previous versions and maintains the same meaning as much as possible. es6 only On the original basis, some new syntax is implemented using reserved words of previous versions, so es6 and es5 can be mixed.

Can es6 and es5 be mixed?

The operating environment of this tutorial: windows10 system, ECMAScript 6.0&&ECMAScript 5.0 version, Dell G3 computer.

es6 and es5 can be mixed and used

Almost all software or protocol upgrades for civilians are as compatible as possible with all previous versions.

That is, ES6 contains the syntax of all previous versions and maintains the same meaning as much as possible. In other words, ES6 only uses the reserved words of previous versions to implement some new syntax on the original basis, and the meaning of the original things remains unchanged.

The difference between es6 and es5

Introduction of system libraries

Es5: Need to be used first require imports the React package, becomes an object, and then makes a real reference;

Es6: You can use the import method to directly implement the system library reference without making an additional class library object

Exporting and referencing a single class

Es5: To export a class to other modules, this is usually achieved through module.exports. When quoting, it is still obtained through the require method;

Es6: You can use export default to achieve the same function, and use the import method to implement import

Note: Import and export of ES5 and ES6 Methods appear in pairs and cannot be mixed.

Define components

Es5: The definition of the component class is implemented through React.createClass;

Es6: Let the component class inherit the React.Component class That's it.

Note: In ES5, parentheses are required after React.createClass, and there must be a semicolon at the end.

There will be no parentheses at the end, and there is no need to add a semicolon.

Internal definition method of component

Es5: The format is

:function(), and a comma needs to be added at the end of the method braces;

Es6: The paragraph [: function] is omitted, and there is no need to add a comma at the end to separate it.

Note: If you use the rules defined by ES6, the outer layer must use [class

# extend React.Component] to declare this class, otherwise an error will be reported.

Define the attribute type and default attribute of the component

Es5: The attribute type and default attribute are implemented through the propTypes member and the getDefaultProps method respectively (these two methods should be Fixed name);

Es6: Use static members uniformly to implement.

Initialize STATE

Es5: The method of initializing state is fixed getInitialState;

Es6: The first method is to directly construct the state function; the second This is equivalent to method rewriting in OC, rewriting the constructor method[Related recommendations: javascript video tutorial,

web front-end###]###

The above is the detailed content of Can es6 and es5 be mixed?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn