1.概述

2.严格模式
es6模块自动采用严格模式
3.export命令
--规定模块的对外接口


4.import命令

5.模块的整体加载

6.export default命令
--为模块指定默认输出

export default就是输出一个叫做default的变量或方法,然后系统允许你为它取任意名字

7.export和import的复合写法
在一个模块中,先输入后输出同一个模块

8.模块的继承

9.跨模块常量

常量较多时,可以使用 export和import的复合写法

10.import()
--提案,引入该函数,实现动态加载,
函数参数是 所要加载的模块的位置,返回一个Promise对象
非模块的脚本也可以使用该方法
import()类似于 Node 的require方法,区别主要是前者是异步加载,后者是同步加载
其适用场合:
1)按需加载
2)条件加载
3)动态的模块路径
注意点:
import()加载模块成功以后,这个模块会作为一个对象,当作then方法的参数。因此,可以使用对象解构赋值的语法,获取输出接口
网友评论