当前位置:网站首页>ES6 模块化
ES6 模块化
2022-07-04 05:46:00 【玉安_ZhangDe】
ES6 模块化 简介
ES6 模块化规范是 浏览器端 与 服务器端 通用的模块化开发规范。它的出现极大的降低了前端开发者的模块化学习成本,开发者不需要再额外学习 AMD(AMD yes !!! XD)、CMD 或 CommonJS等模块化规范。
ES6 模块化规范中定义:
- 每个js文件都是一个独立的模块
- 导入其他模块成员使用 import 关键字
- 向外共享模块成员使用 export 关键字
在node.js中体验 ES6 模块化
- 确保安装了 v14.15.1 或更高版本的node.js
- 在 package.json 的根节点中添加 "type": "module" 节点

![]()
默认导出 和 默认导入
每个js脚本里面只能使用唯一一次 export default ,否则会报错
// 默认导出
// 每个js脚本里面只能使用唯一一次 export default ,否则会报错
let m1 = 10
let m2 = 20
let f1 = () =>{}
export default {
m1,
f1
}// 默认导入
// 路径务必将文件后缀写上
import i1 from './01.默认导出.js'
console.log(i1) ![]()
按需导出 和 按需导入
// 按需导出
export let s1 = 'aaa'
export let s2 = 'ccc'
export const add = x => x+10
// 按需导入
// 传过来发现和当前 js脚本的变量名有冲突,我们可以用 as 更改 名字,只在当前js脚本内有效
import {s1 as ss,s2,add} from './03.按需导出.js'
let s1 = 10
console.log(ss)
console.log(s2)
console.log(s1)
console.log(add(s1))
直接导入
直接导入会执行被导入js脚本的程序

边栏推荐
- js获取对象中嵌套的属性值
- Halcon image calibration enables subsequent image processing to become the same as the template image
- Online shrimp music will be closed in January next year. Netizens call No
- Experience weekly report no. 102 (July 4, 2022)
- Recommended system 1 --- framework
- gslb(global server load balance)技术的一点理解
- 2022 a special equipment related management (elevator) examination questions simulation examination platform operation
- Notepad++ -- display related configurations
- How to use postman to realize simple interface Association [add, delete, modify and query]
- BUU-Pwn-test_ your_ nc
猜你喜欢

VB.net GIF(制作、拆解——优化代码,类库——5)

Programmers don't talk about morality, and use multithreading for Heisi's girlfriend

Take you to quickly learn how to use qsort and simulate qsort
![[high concurrency, high performance and high availability of massive data MySQL practice-7] - memory data drop disk](/img/b9/cf4db4f8a5d2ef3fb344258f0e30f5.jpg)
[high concurrency, high performance and high availability of massive data MySQL practice-7] - memory data drop disk

transformer坑了多少算力
![[QT] create mycombobox click event](/img/5a/ed17567a71f6737891fc7a8273df0a.png)
[QT] create mycombobox click event

input显示当前选择的图片

AWT常用组件、FileDialog文件选择框

【QT】制作MyComboBox点击事件
![[MySQL practice of massive data with high concurrency, high performance and high availability -8] - transaction isolation mechanism of InnoDB](/img/8e/90d08d22a2d340242be2357f662ea4.jpg)
[MySQL practice of massive data with high concurrency, high performance and high availability -8] - transaction isolation mechanism of InnoDB
随机推荐
2022 a special equipment related management (elevator) examination questions simulation examination platform operation
Overview of relevant subclasses of beanfactorypostprocessor and beanpostprocessor
SQL injection - injection based on MSSQL (SQL Server)
js如何将秒转换成时分秒显示
BUU-Crypto-[GUET-CTF2019]BabyRSA
Google Chrome browser will support the function of selecting text translation
Halcon图片标定,使得后续图片处理过后变成与模板图片一样
Signification des lettres du module optique et abréviation des paramètres Daquan
JS string splicing enhancement
How much computing power does transformer have
left_ and_ right_ Net normal version
BUU-Real-[PHP]XXE
"In simple language programming competition (basic)" part 1 Introduction to language Chapter 3 branch structure programming
Enterprise level log analysis system elk (if things backfire, there must be other arrangements)
VB. Net GIF (making and disassembling - optimizing code, class library - 5)
Install pytoch geometric
Introduction to AMBA
gslb(global server load balance)技术的一点理解
卸载Google Drive 硬盘-必须退出程序才能卸载
509. 斐波那契数、爬楼梯所有路径、爬楼梯最小花费