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: 2-ui/2-events/01-introduction-browser-events/article.md
+6-8Lines changed: 6 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -388,7 +388,7 @@ For instance:
388
388
</script>
389
389
```
390
390
391
-
In other words, when `addEventListener` receives and object as the handler, it calls `object.handleEvent(event)` in case of an event.
391
+
In other words, when `addEventListener` receives an object as the handler, it calls `object.handleEvent(event)` in case of an event.
392
392
393
393
We could also use a class for that:
394
394
@@ -418,9 +418,9 @@ We could also use a class for that:
418
418
</script>
419
419
```
420
420
421
-
Here the same object handles both events. Please note that we need to explicitly setup the listeners. The `menu` object only gets `mousedown` and `mouseup` here, not any other types of events.
421
+
Here the same object handles both events. Please note that we need to explicitly setup the events to listen using `addEventListener`. The `menu` object only gets `mousedown` and `mouseup` here, not any other types of events.
422
422
423
-
The method `handleEvent` does not have to handle everything by itself. It can call the corresponding event-specific instead, like this:
423
+
The method `handleEvent` does not have to do all the job by itself. It can call other event-specific methods instead, like this:
424
424
425
425
```html run
426
426
<buttonid="elem">Click me</button>
@@ -456,16 +456,14 @@ There are 3 ways to assign event handlers:
456
456
457
457
1. HTML attribute: `onclick="..."`.
458
458
2. DOM property: `elem.onclick = function`.
459
-
3. Methods `elem.addEventListener(event, handler[, phase])`, to remove:`removeEventListener`.
459
+
3. Methods:`elem.addEventListener(event, handler[, phase])` to add,`removeEventListener` to remove.
460
460
461
461
HTML attributes are used sparingly, because JavaScript in the middle of an HTML tag looks a little bit odd and alien. Also can't write lots of code in there.
462
462
463
463
DOM properties are ok to use, but we can't assign more than one handler of the particular event. In many cases that limitation is not pressing.
464
464
465
-
The last way is the most flexible, but it is also the longest to write. There are few events that only work with it, for instance `transtionend` and `DOMContentLoaded` (to be covered).
465
+
The last way is the most flexible, but it is also the longest to write. There are few events that only work with it, for instance `transtionend` and `DOMContentLoaded` (to be covered). Also `addEventListener` supports objects as event handlers. In that case the method `handleEvent` is called in case of the event.
466
466
467
-
Also `addEventListener` supports objects as event handlers. In that case the method `handleEvent` is called in case of the event.
468
-
469
-
When a handler is called, it gets an event object as the first argument that contains the details about what's happened.
467
+
No matter how you assign the handler -- it gets an event object as the first argument. That object contains the details about what's happened.
470
468
471
469
We'll learn more about events in general and about different types of events in the next chapters.
Copy file name to clipboardExpand all lines: 5-regular-expressions/08-regexp-greedy-and-lazy/article.md
+4-4Lines changed: 4 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -39,20 +39,20 @@ That can be described as "greediness is the cause of all evil".
39
39
To find a match, the regular expression engine uses the following algorithm:
40
40
41
41
- For every position in the string
42
-
- Match the pattern symbol-by-symbol using classes and quantifiers.
42
+
- Match the pattern at that position.
43
43
- If there's no match, go to the next position.
44
44
45
45
These common words do not make it obvious why the regexp fails, so let's elaborate how the search works for the pattern `pattern:".+"`.
46
46
47
47
1. The first pattern character is a quote `pattern:"`.
48
48
49
-
The regular expression engine tries to find it on 0-th position of the source string, but there's `subject:a` there, so no match.
49
+
The regular expression engine tries to find it at the zero position of the source string`subject:a "witch" and her "broom" is one`, but there's `subject:a` there, so there's immediately no match.
50
50
51
-
Then it advances: goes to the 1st, 2nd positions in the source string and tries to find the pattern there, and finally finds the quote at the 3rd position:
51
+
Then it advances: goes to the next positions in the source string and tries to find the first character of the pattern there, and finally finds the quote at the 3rd position:
52
52
53
53

54
54
55
-
2. The quote is detected, and then the engine tries to find a match for the rest of the pattern.
55
+
2. The quote is detected, and then the engine tries to find a match for the rest of the pattern. It tries to see if the rest of the subject string conforms to `pattern:.+"`.
56
56
57
57
In our case the next pattern character is `pattern:.` (a dot). It denotes "any character except a newline", so the next string letter `match:'w'` fits:
0 commit comments