You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 1-js/12-generators-iterators/1-generators/article.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -343,7 +343,7 @@ generator.next(4); // --> pass the result into the generator
343
343
344
344

345
345
346
-
1. The first call `generator.next()`is always without an argument. It starts the execution and returns the result of the first `yield "2+2=?"`. At this point the generator pauses the execution (still on that line).
346
+
1. The first call `generator.next()`should be always made without an argument (the argument is ignored if passed). It starts the execution and returns the result of the first `yield "2+2=?"`. At this point the generator pauses the execution, while staying on the line`(*)`.
347
347
2. Then, as shown at the picture above, the result of `yield` gets into the `question` variable in the calling code.
348
348
3. On `generator.next(4)`, the generator resumes, and `4` gets in as the result: `let result = 4`.
Copy file name to clipboardExpand all lines: 2-ui/1-document/07-modifying-document/article.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -540,7 +540,7 @@ So if we need to add a lot of text into HTML dynamically, and we're at page load
540
540
-`"beforeend"` -- insert `html` into `elem`, at the end,
541
541
-`"afterend"` -- insert `html` right after `elem`.
542
542
543
-
Also there are also similar methods, `elem.insertAdjacentText` and `elem.insertAdjacentElement`, that insert text strings and elements, but they are rarely used.
543
+
Also there are similar methods, `elem.insertAdjacentText` and `elem.insertAdjacentElement`, that insert text strings and elements, but they are rarely used.
544
544
545
545
- To append HTML to the page before it has finished loading:
Copy file name to clipboardExpand all lines: 2-ui/2-events/03-event-delegation/article.md
+5-5Lines changed: 5 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -163,7 +163,7 @@ The handler reads the attribute and executes the method. Take a look at the work
163
163
164
164
Please note that `this.onClick` is bound to `this` in `(*)`. That's important, because otherwise `this` inside it would reference the DOM element (`elem`), not the `Menu` object, and `this[action]` would not be what we need.
165
165
166
-
So, what the delegation gives us here?
166
+
So, what advantages does delegation give us here?
167
167
168
168
```compare
169
169
+ We don't need to write the code to assign a handler to each button. Just make a method and put it in the markup.
@@ -242,13 +242,13 @@ That may become really convenient -- no need to write JavaScript for every such
242
242
243
243
We can combine multiple behaviors on a single element as well.
244
244
245
-
The "behavior" pattern can be an alternative of mini-fragments of JavaScript.
245
+
The "behavior" pattern can be an alternative to mini-fragments of JavaScript.
246
246
247
247
## Summary
248
248
249
249
Event delegation is really cool! It's one of the most helpful patterns for DOM events.
250
250
251
-
It's often used to add same handling for many similar elements, but not only for that.
251
+
It's often used to add the same handling for many similar elements, but not only for that.
252
252
253
253
The algorithm:
254
254
@@ -261,12 +261,12 @@ Benefits:
261
261
```compare
262
262
+ Simplifies initialization and saves memory: no need to add many handlers.
263
263
+ Less code: when adding or removing elements, no need to add/remove handlers.
264
-
+ DOM modifications: we can mass add/remove elements with `innerHTML` and alike.
264
+
+ DOM modifications: we can mass add/remove elements with `innerHTML` and the like.
265
265
```
266
266
267
267
The delegation has its limitations of course:
268
268
269
269
```compare
270
270
- First, the event must be bubbling. Some events do not bubble. Also, low-level handlers should not use `event.stopPropagation()`.
271
-
- Second, the delegation may add CPU load, because the container-level handler reacts on events in any place of the container, no matter if they interest us or not. But usually the load is negligible, so we don't take it into account.
271
+
- Second, the delegation may add CPU load, because the container-level handler reacts on events in any place of the container, no matter whether they interest us or not. But usually the load is negligible, so we don't take it into account.
Copy file name to clipboardExpand all lines: 2-ui/3-event-details/1-mouse-events-basics/article.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -110,7 +110,7 @@ So if we want to support combinations like `key:Ctrl`+click, then for Mac it mak
110
110
111
111
Even if we'd like to force Mac users to `key:Ctrl`+click -- that's kind of difficult. The problem is: a left-click with `key:Ctrl` is interpreted as a *right-click* on MacOS, and it generates the `contextmenu` event, not `click` like Windows/Linux.
112
112
113
-
So if we want users of all operational systems to feel comfortable, then together with `ctrlKey` we should check `metaKey`.
113
+
So if we want users of all operating systems to feel comfortable, then together with `ctrlKey` we should check `metaKey`.
114
114
115
115
For JS-code it means that we should check `if (event.ctrlKey || event.metaKey)`.
Copy file name to clipboardExpand all lines: 2-ui/3-event-details/3-mousemove-mouseover-mouseout-mouseenter-mouseleave/article.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -145,7 +145,7 @@ When the pointer leaves an element -- `mouseleave` triggers.
145
145
```online
146
146
This example is similar to the one above, but now the top element has `mouseenter/mouseleave` instead of `mouseover/mouseout`.
147
147
148
-
As you can see, the only generated events are the ones related to moving the pointer in and out of the top element. Nothing happens when the pointer goes to the child and back. Transitions between descendants are ignores
148
+
As you can see, the only generated events are the ones related to moving the pointer in and out of the top element. Nothing happens when the pointer goes to the child and back. Transitions between descendants are ignored
Copy file name to clipboardExpand all lines: 5-network/02-formdata/article.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -54,14 +54,14 @@ In this example, the server code is not presented, as it's beyound our scope. Th
54
54
We can modify fields in `FormData` with methods:
55
55
56
56
-`formData.append(name, value)` - add a form field with the given `name` and `value`,
57
-
-`formData.append(name, blob, fileName)` - add a field as if it were `<input type="file">`, the third argument `fileName` sets file name (not form field name), as it it were a name of the file in user's filesystem,
57
+
-`formData.append(name, blob, fileName)` - add a field as if it were `<input type="file">`, the third argument `fileName` sets file name (not form field name), as it were a name of the file in user's filesystem,
58
58
-`formData.delete(name)` - remove the field with the given `name`,
59
59
-`formData.get(name)` - get the value of the field with the given `name`,
60
60
-`formData.has(name)` - if there exists a field with the given `name`, returns `true`, otherwise `false`
61
61
62
62
A form is technically allowed to have many fields with the same `name`, so multiple calls to `append` add more same-named fields.
63
63
64
-
There's also method `set`, with the same syntax as `append`. The difference is that `.set` removes all fields with the given `name`, and then appends a new field. So it makes sure there's only field with such `name`, the rest is just like `append`:
64
+
There's also method `set`, with the same syntax as `append`. The difference is that `.set` removes all fields with the given `name`, and then appends a new field. So it makes sure there's only one field with such `name`, the rest is just like `append`:
0 commit comments