import与export
import
是 es6 为 js 模块化提出的新的语法,import (导入)要与 export(导出)结合使用。
用法
a.js
export function test (args) {
// body...
console.log(args);
}
// 默认导出模块,一个文件中只能定义一个
export default function() {...};
export const name = "lyn";
b.js
// _代表引入的export default的内容
import _, { test, name } from "./a.js";
test(`my name is ${name}`);