Skip to content

Commit 44fadd4

Browse files
committed
docs(module): edit module
1 parent b3c64a8 commit 44fadd4

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

docs/module.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,14 @@ import { foo, bar } from 'my_module';
270270

271271
上面代码中,虽然`foo``bar`在两个语句中加载,但是它们对应的是同一个`my_module`实例。也就是说,`import`语句是 Singleton 模式。
272272

273+
目前阶段,通过 Babel 转码,CommonJS 模块的`require`命令和 ES6 模块的`import`命令,可以写在同一个模块里面,但是最好不要这样做。因为`import`在静态解析阶段执行,所以它是一个模块之中最早执行的。下面的代码可能不会得到预期结果。
274+
275+
```javascript
276+
require('core-js/modules/es6.symbol');
277+
require('core-js/modules/es6.promise');
278+
import React from 'React';
279+
```
280+
273281
## 模块的整体加载
274282

275283
除了指定加载某个输出值,还可以使用整体加载,即用星号(`*`)指定一个对象,所有输出值都加载在这个对象上面。

0 commit comments

Comments
 (0)