Last active
May 25, 2018 11:38
Revisions
-
ibeeger revised this gist
May 25, 2018 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -51,7 +51,7 @@ export { foo as FOO, bar as BAR } from "baz"; export * from "baz"; </pre> ### import <pre> import { foo } from "foo"; -
ibeeger created this gist
May 25, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,90 @@ ### export 基本的两种用法: <pre>export function foo() { // .. } export var awesome = 42; var bar = [1,2,3]; export { bar }; </pre> <pre> function foo() { // .. } var awesome = 42; var bar = [1,2,3]; export { foo, awesome, bar }; </pre> 导出的时候重命名: <pre> function foo() { .. } export { foo as bar }; </pre> 默认导出,每个模块只能有一个默认导出: <pre> function foo(..) { // .. } export default foo; export{ foo as default }; </pre> 混合默认导出和普通的导出: <pre> function foo() { .. } function bar() { .. } function baz() { .. } export { foo as default, bar, baz, .. }; </pre> 从其他模块导出: <pre> export { foo, bar } from "baz"; export { foo as FOO, bar as BAR } from "baz"; export * from "baz"; </pre> ###import <pre> import { foo } from "foo"; foo(); </pre> <pre> import { foo as theFooFunc } from "foo"; theFooFunc();</pre> <pre>import foo from "foo"; // or: import { default as foo } from "foo";</pre> <pre>export default function foo() { .. } export function bar() { .. } export function baz() { .. } import FOOFN, { bar, baz as BAZ } from "foo"; FOOFN(); bar(); BAZ();</pre> <pre>export function bar() { .. } export var x = 42; export function baz() { .. } import * as foo from "foo"; foo.bar(); foo.x; // 42 foo.baz();</pre> import有一个hoisted的过程,和var声明变量一样: <pre> foo(); import { foo } from "foo";</pre>