Tekkaman

导航

 

ES2015 import

  The import statement is used to import functions, objects or primitives that have been exported from an external module, another script, etc.

import defaultMember from "module-name";
import * as name from "module-name";
import { member } from "module-name";
import { member as alias } from "module-name";
import { member1 , member2 } from "module-name";
import { member1 , member2 as alias2 , [...] } from "module-name";
import defaultMember, { member [ , [...] ] } from "module-name";
import defaultMember, * as name from "module-name";
import "module-name";

 

  用于导出已经声明为export的function、object。

  注意不存在import * from 'module-name'的用法,只能是import * as name from 'module-name'。

  注意导入export default,应当使用 import name from 'module-name'

  注意导入export,应该加上{},如import {name} from 'module-name'

ES2015 export

  There are two different types of export, named and default. You can have multiple named exports per module but only one default export.

 

  The export statement is used to export functions, objects or primitives from a given file (or module).

export { myFunction }; // exports a function declared earlier
export const foo = Math.sqrt(2); // exports a constant

 Concerning the default export, there is only a single default export per module. A default export can be a function, a class, an object or anything else. 

export default function() {} // or 'export default class {}'
// there is no semi-colon here
export default class {}

 

参考:

1、https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import

2、https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export

posted on 2017-04-29 13:15  Tekkaman  阅读(1323)  评论(0编辑  收藏  举报