Skip to content

Commit 8d44e73

Browse files
committed
Merge pull request DrkSephy#18 from hyb175/master
Modify named imports
2 parents 7ccc15a + 9c12d13 commit 8d44e73

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

README.md

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -361,27 +361,41 @@ import `underscore`
361361

362362
> It is important to note that simply **importing an entire file will execute all code at the top level of that file**.
363363
364-
We can also use destructuring to import a list of values from a file:
364+
Similar to Python, we have named imports:
365365

366366
```javascript
367367
import { sumTwo, sumThree } from 'math/addition'
368368
```
369369

370-
Similar to Python, we have named imports:
370+
We can also rename the named imports:
371371

372372
```javascript
373-
import {
374-
sumTwo as addTwoNumbers,
373+
import {
374+
sumTwo as addTwoNumbers,
375375
sumThree as sumThreeNumbers
376376
} from 'math/addition'
377377
```
378378

379-
And lastly, we can **import all the things**:
379+
In addition, we can **import all the things** (also called namespace import):
380380

381381
```javascript
382382
import * as util from 'math/addition'
383383
```
384384

385+
Lastly, we can use destructuring to import a list of values from a file:
386+
387+
```javascript
388+
import * as addtionUtil from 'math/addtion';
389+
const { sumTwo, sumThree } = addtionUtil;
390+
```
391+
392+
or when we are importing the default object but we want to grab some of the functions on the object:
393+
394+
```javascript
395+
import React from 'react';
396+
const { Component, PropTypes } = React;
397+
```
398+
385399
> **Note**: Values that are exported are **bindings**, not references. Therefore, changing the binding of a variable in one module will affect the value within the exported module. Avoid changing the public interface of these exported values.
386400
387401
<sup>[(back to table of contents)](#table-of-contents)</sup>

0 commit comments

Comments
 (0)