Skip to content

Commit 899a3ce

Browse files
committed
fixes
1 parent f5f31e8 commit 899a3ce

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

1-js/13-modules/02-import-export/article.md

+15-11
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ Well, there are few reasons.
103103
export function becomeSilent() { ... }
104104
```
105105

106-
Now if we in fact need only one of them in our project:
106+
Now if we only use one of `lib.js` functions in our project:
107107
```js
108108
// 📁 main.js
109109
import {sayHi} from './lib.js';
@@ -218,8 +218,7 @@ export default function(user) { // no function name
218218
export default ['Jan', 'Feb', 'Mar','Apr', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
219219
```
220220

221-
That's fine, because `export default` is only one per file, so `import` always knows what to import.
222-
Contrary to that, omitting a name for named imports would be an error:
221+
That's fine, because `export default` is only one per file. Contrary to that, omitting a name for named imports would be an error:
223222
224223
```js
225224
export class { // Error! (non-default export needs a name)
@@ -229,9 +228,9 @@ export class { // Error! (non-default export needs a name)
229228
230229
### "Default" alias
231230
232-
The "default" word is a kind of "alias" for the default export, for scenarios when we need to reference it somehow.
231+
The "default" keyword is used as an "alias" for the default export, for standalone exports and other scenarios when we need to reference it.
233232
234-
For example, if we already have a function declared, that's how to `export default` it:
233+
For example, if we already have a function declared, that's how to `export default` it (separately from the definition):
235234

236235
```js
237236
function sayHi(user) {
@@ -278,20 +277,23 @@ new User('John');
278277

279278
### Should I use default exports?
280279

281-
One should be careful about using default exports, because they are somewhat more different to maintain.
280+
One should be careful about using default exports, because they are more difficult to maintain.
282281

283282
Named exports are explicit. They exactly name what they import, so we have that information from them, that's a good thing.
284283
285284
Also, named exports enforce us to use exactly the right name to import:
286285
287286
```js
288287
import {User} from './user.js';
288+
// import {MyUser} won't work, the name must be {User}
289289
```
290290
291-
For default exports, we need to create a name on our own:
291+
For default exports, we always choose the name when importing:
292292
293293
```js
294-
import MyUser from './user.js'; // could be import Anything..., and it'll work
294+
import User from './user.js'; // works
295+
import MyUser from './user.js'; // works too
296+
// could be import Anything..., and it'll be work
295297
```
296298
297299
So, there's a little bit more freedom that can be abused, so that team members may use different names for the same thing.
@@ -409,16 +411,18 @@ Import:
409411
- `import {default as x} from "mod"`
410412
- Everything:
411413
- `import * as obj from "mod"`
412-
- Only fetch/evaluate the module, don't import:
414+
- Import the module (it runs), but do not assign it to a variable:
413415
- `import "mod"`
414416
415-
We can put import/export statements below or after other code, that doesn't matter.
417+
We can put import/export statements at the top or at the bottom of a script, that doesn't matter.
416418
417419
So this is technically fine:
418420
```js
419421
sayHi();
420422

421-
import {sayHi} from './say.js'; // import at the end of the file
423+
// ...
424+
425+
import {sayHi} from './say.js'; // import at the end of the script
422426
```
423427
424428
In practice imports are usually at the start of the file, but that's only for better convenience.

2-ui/2-events/01-introduction-browser-events/article.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,9 @@ button.onclick = sayThanks;
160160
button.onclick = sayThanks();
161161
```
162162

163-
If we add brackets, then `sayThanks()` -- will be the *result* of the function execution, so `onclick` in the last code becomes `undefined` (the function returns nothing). That won't work.
163+
If we add parentheses, `sayThanks()` -- is a function call. So the last line actually takes the *result* of the function execution, that is `undefined` (as the function returns nothing), and assigns it to `onclick`. That doesn't work.
164164

165-
...But in the markup we do need the brackets:
165+
...But in the markup we do need the parentheses:
166166

167167
```html
168168
<input type="button" id="button" onclick="sayThanks()">
@@ -351,7 +351,7 @@ Some properties of `event` object:
351351
: Event type, here it's `"click"`.
352352
353353
`event.currentTarget`
354-
: Element that handled the event. That's exactly the same as `this`, unless you bind `this` to something else, and then `event.currentTarget` becomes useful.
354+
: Element that handled the event. That's exactly the same as `this`, unless the handler is an arrow function, or its `this` is bound to something else, then `event.currentTarget` becomes useful.
355355
356356
`event.clientX / event.clientY`
357357
: Window-relative coordinates of the cursor, for mouse events.

0 commit comments

Comments
 (0)