Introduction and export of commonJS and es6 specifications
This time I will bring you the introduction and export of commonJS and es6 specifications. What are the precautions for the introduction and export of commonJS and es6 specifications. The following is a practical case, let's take a look.
Definition in index.js:
var info = { name = 'sisi' };
1.When defining variables, do not use objectvariable name, as unknown errors may occur. .
2. When using export {info} for output, the import must be in the form of import {info} from index.js, and the curly brackets cannot be omitted.
3. When the output is in the form of export{info as vm}, the info interface can no longer be used for import, and only the vm interface can be used, that is,
import {vm} from index.js
4. Key points: The output uses module.exports = info When introducing info, you can also use import.
import info from index.js
cannot be used
import {info} from index.js
Of course, in this case, use require ;Also correct
var info = require('index.js');
5. Compare with the fourth item above, if the output uses es6 export. That is, export {info}; or export default info; then the module must use import to introduce info, and require will not work.
6. When using export output, the import must have {}, for example, demo.js
export const str = 'sisi'; export function func(){ console.log('sisi'); }
must be imported with:
import {str} from 'demo'; 或 import {str, func} from 'demo';
cannot be used
export default const str = 'sisi';
But when using
export default const str = 'sisi';
to import, you can use
import str from 'demo';
because there can only be one export default
es6 { export : '可以输出多个,输出方式为 {}' , export default : ' 只能输出一个 ,可以与export 同时输出,但是不建议这么做', 解析阶段确定对外输出的接口,解析阶段生成接口, 模块不是对象,加载的不是对象, 可以单独加载其中的某个接口(方法), 静态分析,动态引用,输出的是值的引用,值改变,引用也改变,即原来模块中的值改变则该加载的值也改变, this 指向undefined } commonJS { module.exports = ... : '只能输出一个,且后面的会覆盖上面的' , exports. ... : ' 可以输出多个', 运行阶段确定接口,运行时才会加载模块, 模块是对象,加载的是该对象, 加载的是整个模块,即将所有的接口全部加载进来, 输出是值的拷贝,即原来模块中的值改变不会影响已经加载的该值, this 指向当前模块 }
in a file or module. I believe I read the case in this article. You have mastered the method. For more exciting information, please pay attention to other related articles on the php Chinese website!
Related reading:
Entry, output, module analysis of webpack3.x
The above is the detailed content of Introduction and export of commonJS and es6 specifications. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

With the continuous rise of social media, Douyin, as a popular short video platform, has attracted a large number of users. On Douyin, users can not only show their lives but also interact with other users. In this interaction, emoticons have gradually become an important way for users to express their emotions. 1. How to get Douyin private message emoticons on WeChat? First of all, to get private message emoticons on the Douyin platform, you need to log in to your Douyin account, then browse and select the emoticons you like. You can choose to send them to friends or collect them yourself. After receiving the emoticon package on Douyin, you can long press the emoticon package through the private message interface, and then select the "Add to Emoticon" function. In this way, you can add this emoticon package to Douyin’s emoticon library. 3. Next, we need to add the words in the Douyin emoticon library

How to use WebSocket and JavaScript to implement an online speech recognition system Introduction: With the continuous development of technology, speech recognition technology has become an important part of the field of artificial intelligence. The online speech recognition system based on WebSocket and JavaScript has the characteristics of low latency, real-time and cross-platform, and has become a widely used solution. This article will introduce how to use WebSocket and JavaScript to implement an online speech recognition system.

Listening to music is a very common thing, I believe many friends will do it no matter where they are. What software do you usually use to listen to music? Do you use QQ Music like me? I currently use QQ Music to listen to songs, and it can be used not only on mobile phones, but also on Mac computers. In addition to listening to songs online, we can also download our favorite songs from QQ Music to the computer. However, the songs downloaded from QQ Music for Mac are not in the format we need. What we need is music in MP3 format. So how to export the songs downloaded from QQ Music for Mac to MP3 format? How to export and convert songs downloaded from QQ Music for Mac to MP3 format? If you want to export and convert songs downloaded from QQ Music for Mac to MP

xmind is a very practical mind mapping software. It is a map form made using people's thinking and inspiration. After we create the xmind file, we usually convert it into a pdf file format to facilitate everyone's dissemination and use. Then How to export xmind files to pdf files? Below are the specific steps for your reference. 1. First, let’s demonstrate how to export the mind map to a PDF document. Select the [File]-[Export] function button. 2. Select [PDF document] in the newly appeared interface and click the [Next] button. 3. Select settings in the export interface: paper size, orientation, resolution and document storage location. After completing the settings, click the [Finish] button. 4. If you click the [Finish] button

WebSocket and JavaScript: Key technologies for realizing real-time monitoring systems Introduction: With the rapid development of Internet technology, real-time monitoring systems have been widely used in various fields. One of the key technologies to achieve real-time monitoring is the combination of WebSocket and JavaScript. This article will introduce the application of WebSocket and JavaScript in real-time monitoring systems, give code examples, and explain their implementation principles in detail. 1. WebSocket technology

1. First, open the design plan to be processed in Kujiale and click on the construction drawings under the drawing list above. 2. Then click to select the full-color floor plan. 3. Then hide the unnecessary furniture in the drawing, leaving only the furniture that needs to be exported. 4. Finally, click Download.

Introduction to how to use JavaScript and WebSocket to implement a real-time online ordering system: With the popularity of the Internet and the advancement of technology, more and more restaurants have begun to provide online ordering services. In order to implement a real-time online ordering system, we can use JavaScript and WebSocket technology. WebSocket is a full-duplex communication protocol based on the TCP protocol, which can realize real-time two-way communication between the client and the server. In the real-time online ordering system, when the user selects dishes and places an order

How to use WebSocket and JavaScript to implement an online reservation system. In today's digital era, more and more businesses and services need to provide online reservation functions. It is crucial to implement an efficient and real-time online reservation system. This article will introduce how to use WebSocket and JavaScript to implement an online reservation system, and provide specific code examples. 1. What is WebSocket? WebSocket is a full-duplex method on a single TCP connection.
