当前位置:网站首页>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脚本的程序
边栏推荐
- Zhanrui tankbang | jointly build, cooperate and win-win zhanrui core ecology
- left_ and_ right_ Net normal version
- How to configure static IP for Kali virtual machine
- [high concurrency, high performance and high availability of massive data MySQL practice-7] - memory data drop disk
- Luogu deep foundation part 1 Introduction to language Chapter 5 array and data batch storage
- js arguments参数使用和详解
- 谷歌 Chrome 浏览器将支持选取文字翻译功能
- Supplement the JS of a video website to decrypt the video
- 19. Framebuffer application programming
- [microservice] Nacos cluster building and loading file configuration
猜你喜欢
AWT介绍
卸载Google Drive 硬盘-必须退出程序才能卸载
Etcd database source code analysis - initialization overview
Flask
BUU-Crypto-[HDCTF2019]basic rsa
BUU-Crypto-[GUET-CTF2019]BabyRSA
接地继电器DD-1/60
Compound nonlinear feedback control (2)
The data mark is a piece of fat meat, and it is not only China Manfu technology that focuses on this meat
冲击继电器JC-7/11/DC110V
随机推荐
el-select如何实现懒加载(带搜索功能)
How to use postman to realize simple interface Association [add, delete, modify and query]
Kubernets first meeting
The data mark is a piece of fat meat, and it is not only China Manfu technology that focuses on this meat
[microservice] Nacos cluster building and loading file configuration
VB. Net simple processing pictures, black and white (class library - 7)
【微服务】Nacos集群搭建以及加载文件配置
Simulink and Arduino serial port communication
FreeRTOS 中 RISC-V-Qemu-virt_GCC 的 锁机制 分析
[high concurrency, high performance and high availability of massive data MySQL practice-7] - memory data drop disk
Leetcode 184 Employees with the highest wages in the Department (July 3, 2022)
Design and implementation of tcp/ip series overview
Gridview出现滚动条,组件冲突,如何解决
Risc-v-qemu-virt in FreeRTOS_ Lock mechanism analysis of GCC
Arc135 C (the proof is not very clear)
Flask
JS arguments parameter usage and explanation
检漏继电器JY82-2P
Zzulioj:1201: mode problem
Compound nonlinear feedback control (2)