zl程序教程

您现在的位置是:首页 >  后端

当前栏目

[ES6] ES6 Modules (ES2015) - Import and Export

ES6 and import EXPORT modules
2023-09-14 09:00:55 时间

ES6 (ES2015) introduces a standardized module format to Javascript. We'll take a look at the various forms of defining and importing modules. Using Webpack to bundle up our modules and Babel to transpile our ES6 into ES5, we'll put this new module syntax to work within our project. Then we'll examine how to import 3rd party packages from npm, importing lodash with the _ underscore alias using the ES6 module syntax.

 

Some Common Import/Export Variations

 

import {someFunction} from 'someModule';

import {someFunction as someAlias} from 'someModule';

import * as someModule from 'someModule';

export function someFunction() {/* */};

function someFunction() {/* */}; export {someFunction};

function someFunction() {/* */}; export {someFunction as someAlias};