What is the usage of import in es6

WBOY
Release: 2022-03-31 17:25:19
Original
2643 people have browsed it

In es6, import is used to load another module containing an export interface in a module; after using the export command to define the external interface of the module, the JS file can load the module through the import command. The syntax is: "import export module interface from js file".

What is the usage of import in es6

The operating environment of this tutorial: Windows 10 system, ECMAScript version 6.0, Dell G3 computer.

What is the usage of import in es6

ES6 module mainly has two functions: export and import

export is used to output this module externally (a file can be understood as a Module) variable interface

import is used to load another module containing an export interface in a module.

That is to say, after using the export command to define the external interface of the module, other JS files can load this module (file) through the import command.

As shown below (assuming files a and b are in the same directory)

What is the usage of import in es6

What is the usage of import in es6

a.js file can also be pressed The export syntax is written as follows, but it is not as intuitive as the above and is not recommended.

// a.js
export var sex="boy";export var echo=function(value){
  console.log(value)
}
//因为function echo(){}等价于 var echo=function(){}所以也可以写成
export function echo(value){
   console.log(value)
}
Copy after login

[Related recommendations: javascript video tutorial, web front-end

The above is the detailed content of What is the usage of import in es6. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
es6
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template