mirror of
https://github.com/ruanyf/es6tutorial.git
synced 2025-05-24 18:32:22 +00:00
docs(module): edit module
This commit is contained in:
parent
b3c64a86fc
commit
44fadd4268
@ -270,6 +270,14 @@ import { foo, bar } from 'my_module';
|
||||
|
||||
上面代码中,虽然`foo`和`bar`在两个语句中加载,但是它们对应的是同一个`my_module`实例。也就是说,`import`语句是 Singleton 模式。
|
||||
|
||||
目前阶段,通过 Babel 转码,CommonJS 模块的`require`命令和 ES6 模块的`import`命令,可以写在同一个模块里面,但是最好不要这样做。因为`import`在静态解析阶段执行,所以它是一个模块之中最早执行的。下面的代码可能不会得到预期结果。
|
||||
|
||||
```javascript
|
||||
require('core-js/modules/es6.symbol');
|
||||
require('core-js/modules/es6.promise');
|
||||
import React from 'React';
|
||||
```
|
||||
|
||||
## 模块的整体加载
|
||||
|
||||
除了指定加载某个输出值,还可以使用整体加载,即用星号(`*`)指定一个对象,所有输出值都加载在这个对象上面。
|
||||
|
Loading…
x
Reference in New Issue
Block a user