javascript ES6模块

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript ES6模块相关的知识,希望对你有一定的参考价值。

// the module and two functions are exported
export const print(message) => log(message, new Date())

export const log(message, timestamp) =>
  console.log(`${timestamp.toString()}: ${message}`)


// one variable is exported from a module
const freel = new Expedition("Mt. Freel", 2, ["water", "snack"])

export default freel


// modules can be used in other JavaScript files using the import statement
// modules with multiple exports can utilise object destructuring
// modules that use export default are imported into a single variable
import {print, log} from './text-helpers'
import freel from './mt-freel'

// modules can be scoped locally under different variable names
import { print as p, log as l} from './text-helpers'

// can also import everything as a single variable
import * as fns from './text-helpers'

以上是关于javascript ES6模块的主要内容,如果未能解决你的问题,请参考以下文章

javascript ES6模块

基于ES6,使用ReactWebpackBabel构建模块化JavaScript应用

JavaScript模块(ES6 module)化总结(import())

JavaScript模块(ES6 module)化总结(import())

在 Javascript ES6 模块中访问 Vuex 操作

如何处理作为 ES6 模块导入的 JavaScript 文件的缓存