我们知道在ESM中可以定义模块:
export default {
a: 1,
b: 2,
c: () => 3
};
export const d = 4;
export const e = 5;
引用时候:
import others, { e } from './others';
// 1.import others 【引入export default】引入后可用: others.a others.b others.c
// 2.import { e } 【引入export】
今天看到一种引入:* 的方式,请问这个是什么意思呢?
import * as path from "path";
就是把所有的
export const
暴露出来的属性和方法都整合到path
这个变量下,就可以通过path.d
、path.e
去调用了(不包括export default
暴露出来的属性和方法)。可以算是比较基础的
ESM
引入的语法了。参考文档
模块的整体加载 | Module 的语法 - ECMAScript 6入门