Skip to content

Commit 90679b5

Browse files
committed
# Conflicts: # 1-js/05-data-types/01-primitives-methods/article.md # 9-regular-expressions/02-regexp-methods/article.md # 9-regular-expressions/07-regexp-escaping/article.md # 9-regular-expressions/08-regexp-greedy-and-lazy/3-find-html-comments/solution.md # 9-regular-expressions/09-regexp-quantifiers/article.md # 9-regular-expressions/10-regexp-backreferences/article.md # 9-regular-expressions/10-regexp-greedy-and-lazy/article.md # 9-regular-expressions/11-regexp-alternation/article.md # 9-regular-expressions/12-regexp-anchors/article.md # 9-regular-expressions/14-regexp-lookahead-lookbehind/article.md # 9-regular-expressions/15-regexp-infinite-backtracking-problem/article.md
2 parents 1e62f65 + 3dd8ca0 commit 90679b5

101 files changed

Lines changed: 2864 additions & 2384 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1-js/04-object-basics/04-object-methods/article.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ It's common that an object method needs to access the information stored in the
9898

9999
For instance, the code inside `user.sayHi()` may need the name of the `user`.
100100

101-
**To access the object, a method can use the `this` keyword.**
101+
**To access the object, a method can use `this` keyword.**
102102

103103
The value of `this` is the object "before dot", the one used to call the method.
104104

@@ -167,9 +167,9 @@ If we used `this.name` instead of `user.name` inside the `alert`, then the code
167167

168168
## "this" is not bound
169169

170-
In JavaScript, "this" keyword behaves unlike most other programming languages. It can be used in any function.
170+
In JavaScript, keyword `this` behaves unlike most other programming languages. It can be used in any function.
171171

172-
There's no syntax error in the code like that:
172+
There's no syntax error in the following example:
173173

174174
```js
175175
function sayHi() {
@@ -220,13 +220,13 @@ In this case `this` is `undefined` in strict mode. If we try to access `this.nam
220220

221221
In non-strict mode the value of `this` in such case will be the *global object* (`window` in a browser, we'll get to it later in the chapter [](info:global-object)). This is a historical behavior that `"use strict"` fixes.
222222

223-
Usually such call is an programming error. If there's `this` inside a function, it expects to be called in an object context.
223+
Usually such call is a programming error. If there's `this` inside a function, it expects to be called in an object context.
224224
````
225225
226226
```smart header="The consequences of unbound `this`"
227227
If you come from another programming language, then you are probably used to the idea of a "bound `this`", where methods defined in an object always have `this` referencing that object.
228228
229-
In JavaScript `this` is "free", its value is evaluated at call-time and does not depend on where the method was declared, but rather on what's the object "before the dot".
229+
In JavaScript `this` is "free", its value is evaluated at call-time and does not depend on where the method was declared, but rather on what object is "before the dot".
230230
231231
The concept of run-time evaluated `this` has both pluses and minuses. On the one hand, a function can be reused for different objects. On the other hand, greater flexibility opens a place for mistakes.
232232

1-js/05-data-types/03-string/article.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ let guestList = "Guests: // Error: Unexpected token ILLEGAL
5050

5151
Single and double quotes come from ancient times of language creation when the need for multiline strings was not taken into account. Backticks appeared much later and thus are more versatile.
5252

53-
Backticks also allow us to specify a "template function" before the first backtick. The syntax is: <code>func&#96;string&#96;</code>. The function `func` is called automatically, receives the string and embedded expressions and can process them. You can read more about it in the [docs](mdn:/JavaScript/Reference/Template_literals#Tagged_template_literals). This is called "tagged templates". This feature makes it easier to wrap strings into custom templating or other functionality, but it is rarely used.
53+
Backticks also allow us to specify a "template function" before the first backtick. The syntax is: <code>func&#96;string&#96;</code>. The function `func` is called automatically, receives the string and embedded expressions and can process them. You can read more about it in the [docs](mdn:/JavaScript/Reference/Template_literals#Tagged_templates). This is called "tagged templates". This feature makes it easier to wrap strings into custom templating or other functionality, but it is rarely used.
5454

5555
## Special characters
5656

1-js/05-data-types/05-array-methods/article.md

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -655,31 +655,37 @@ arr.map(func, thisArg);
655655

656656
The value of `thisArg` parameter becomes `this` for `func`.
657657

658-
For instance, here we use an object method as a filter and `thisArg` helps with that:
658+
For example, here we use a method of `army` object as a filter, and `thisArg` passes the context:
659659

660660
```js run
661-
let user = {
662-
age: 18,
663-
younger(otherUser) {
664-
return otherUser.age < this.age;
661+
let army = {
662+
minAge: 18,
663+
maxAge: 27,
664+
canJoin(user) {
665+
return user.age >= this.minAge && user.age < this.maxAge;
665666
}
666667
};
667668

668669
let users = [
669-
{age: 12},
670670
{age: 16},
671-
{age: 32}
671+
{age: 20},
672+
{age: 23},
673+
{age: 30}
672674
];
673675

674676
*!*
675-
// find all users younger than user
676-
let youngerUsers = users.filter(user.younger, user);
677+
// find users, for who army.canJoin returns true
678+
let soldiers = users.filter(army.canJoin, army);
677679
*/!*
678680

679-
alert(youngerUsers.length); // 2
681+
alert(soldiers.length); // 2
682+
alert(soldiers[0].age); // 20
683+
alert(soldiers[1].age); // 23
680684
```
681685

682-
In the call above, we use `user.younger` as a filter and also provide `user` as the context for it. If we didn't provide the context, `users.filter(user.younger)` would call `user.younger` as a standalone function, with `this=undefined`. That would mean an instant error.
686+
If in the example above we used `users.filter(army.canJoin)`, then `army.canJoin` would be called as a standalone function, with `this=undefined`, thus leading to an instant error.
687+
688+
A call to `users.filter(army.canJoin, army)` can be replaced with `users.filter(user => army.canJoin(user))`, that does the same. The former is used more often, as it's a bit easier to understand for most people.
683689

684690
## Summary
685691

1-js/05-data-types/10-destructuring-assignment/article.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ alert(item1); // Cake
403403
alert(item2); // Donut
404404
```
405405
406-
The whole `options` object except `extra` that was not mentioned, is assigned to corresponding variables:
406+
All properties of `options` object except `extra` that is absent in the left part, are assigned to corresponding variables:
407407
408408
![](destructuring-complex.svg)
409409

1-js/06-advanced-functions/08-settimeout-setinterval/article.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ We may decide to execute a function not right now, but at a certain time later.
44

55
There are two methods for it:
66

7-
- `setTimeout` allows to run a function once after the interval of time.
8-
- `setInterval` allows to run a function regularly with the interval between the runs.
7+
- `setTimeout` allows us to run a function once after the interval of time.
8+
- `setInterval` allows us to run a function repeatedly, starting after the interval of time, then repeating continuously at that interval.
99

1010
These methods are not a part of JavaScript specification. But most environments have the internal scheduler and provide these methods. In particular, they are supported in all browsers and Node.js.
1111

@@ -239,9 +239,9 @@ There's a side-effect. A function references the outer lexical environment, so,
239239

240240
There's a special use case: `setTimeout(func, 0)`, or just `setTimeout(func)`.
241241

242-
This schedules the execution of `func` as soon as possible. But scheduler will invoke it only after the current code is complete.
242+
This schedules the execution of `func` as soon as possible. But the scheduler will invoke it only after the currently executing script is complete.
243243

244-
So the function is scheduled to run "right after" the current code.
244+
So the function is scheduled to run "right after" the current script.
245245

246246
For instance, this outputs "Hello", then immediately "World":
247247

@@ -251,7 +251,7 @@ setTimeout(() => alert("World"));
251251
alert("Hello");
252252
```
253253

254-
The first line "puts the call into calendar after 0ms". But the scheduler will only "check the calendar" after the current code is complete, so `"Hello"` is first, and `"World"` -- after it.
254+
The first line "puts the call into calendar after 0ms". But the scheduler will only "check the calendar" after the current script is complete, so `"Hello"` is first, and `"World"` -- after it.
255255

256256
There are also advanced browser-related use cases of zero-delay timeout, that we'll discuss in the chapter <info:event-loop>.
257257

@@ -286,10 +286,10 @@ For server-side JavaScript, that limitation does not exist, and there exist othe
286286

287287
## Summary
288288

289-
- Methods `setInterval(func, delay, ...args)` and `setTimeout(func, delay, ...args)` allow to run the `func` regularly/once after `delay` milliseconds.
290-
- To cancel the execution, we should call `clearInterval/clearTimeout` with the value returned by `setInterval/setTimeout`.
291-
- Nested `setTimeout` calls is a more flexible alternative to `setInterval`, allowing to set the time *between* executions more precisely.
292-
- Zero delay scheduling with `setTimeout(func, 0)` (the same as `setTimeout(func)`) is used to schedule the call "as soon as possible, but after the current code is complete".
289+
- Methods `setTimeout(func, delay, ...args)` and `setInterval(func, delay, ...args)` allow us to run the `func` once/regularly after `delay` milliseconds.
290+
- To cancel the execution, we should call `clearTimeout/clearInterval` with the value returned by `setTimeout/setInterval`.
291+
- Nested `setTimeout` calls is a more flexible alternative to `setInterval`, allowing us to set the time *between* executions more precisely.
292+
- Zero delay scheduling with `setTimeout(func, 0)` (the same as `setTimeout(func)`) is used to schedule the call "as soon as possible, but after the current script is complete".
293293
- The browser limits the minimal delay for five or more nested call of `setTimeout` or for `setInterval` (after 5th call) to 4ms. That's for historical reasons.
294294

295295
Please note that all scheduling methods do not *guarantee* the exact delay.

1-js/06-advanced-functions/09-call-apply-decorators/03-debounce/task.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ importance: 5
66

77
The result of `debounce(f, ms)` decorator should be a wrapper that passes the call to `f` at maximum once per `ms` milliseconds.
88

9-
In other words, when we call a "debounced" function, it guarantees that all other future in the closest `ms` milliseconds will be ignored.
9+
In other words, when we call a "debounced" function, it guarantees that all future calls to the function made less than `ms` milliseconds after the previous call will be ignored.
1010

1111
For instance:
1212

@@ -21,4 +21,4 @@ setTimeout( () => f(4), 1100); // runs
2121
setTimeout( () => f(5), 1500); // ignored (less than 1000 ms from the last run)
2222
```
2323

24-
In practice `debounce` is useful for functions that retrieve/update something when we know that nothing new can be done in such a short period of time, so it's better not to waste resources.
24+
In practice `debounce` is useful for functions that retrieve/update something when we know that nothing new can be done in such a short period of time, so it's better not to waste resources.

1-js/09-classes/02-class-inheritance/article.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ In the example below a non-method syntax is used for comparison. `[[HomeObject]]
513513
514514
```js run
515515
let animal = {
516-
eat: function() { // should be the short syntax: eat() {...}
516+
eat: function() { // intentially writing like this instead of eat() {...
517517
// ...
518518
}
519519
};

1-js/12-generators-iterators/1-generators/01-pseudo-random-generator/solution.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,4 @@ alert(generator()); // 282475249
3535
alert(generator()); // 1622650073
3636
```
3737

38-
That also works. But then we loose ability to iterate with `for..of` and to use generator composition, that may be useful elsewhere.
38+
That also works. But then we lose ability to iterate with `for..of` and to use generator composition, that may be useful elsewhere.

1-js/99-js-misc/01-proxy/article.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ What can we intercept with them?
4747

4848
For most operations on objects, there's a so-called "internal method" in JavaScript specificaiton, that describes on the lowest level, how it works. For instance, `[[Get]]` - the internal method to read a property, `[[Set]]` -- the internal method to write a property, and so on. These methods are only used in the specification, we can't call them directly by name.
4949

50-
Proxy traps inercept invocations of these methods. They are listed in [Proxy specification](https://tc39.es/ecma262/#sec-proxy-object-internal-methods-and-internal-slots) and in the table below.
50+
Proxy traps intercept invocations of these methods. They are listed in [Proxy specification](https://tc39.es/ecma262/#sec-proxy-object-internal-methods-and-internal-slots) and in the table below.
5151

5252
For every internal method, there's a trap in this table: the name of the method that we can add to `handler` parameter of `new Proxy` to intercept the operation:
5353

@@ -95,7 +95,7 @@ It triggers when a property is read, with following arguments:
9595

9696
- `target` -- is the target object, the one passed as the first argument to `new Proxy`,
9797
- `property` -- property name,
98-
- `receiver` -- if the target property is a getter, then `receiver` is the object that's going to be used as `this` in its call. Usually that's the `proxy` object itself (or an object that inherits from it, if we inherit from proxy). Right now we don't need this argument, will be explained in more details letter.
98+
- `receiver` -- if the target property is a getter, then `receiver` is the object that's going to be used as `this` in its call. Usually that's the `proxy` object itself (or an object that inherits from it, if we inherit from proxy). Right now we don't need this argument, will be explained in more details later.
9999

100100
Let's use `get` to implement default values for an object.
101101

2-ui/3-event-details/3-mousemove-mouseover-mouseout-mouseenter-mouseleave/article.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,7 @@ Also move the pointer into the child `div`, and then move it out quickly down th
6767
```
6868

6969
```smart header="If `mouseover` triggered, there must be `mouseout`"
70-
In case of fast mouse movements, intermediate elements may be ignores, but one thing we know for sure: elements can be only skipped as a whole.
71-
72-
If the pointer "officially" entered an element with `mouseover`, then upon leaving it we always get `mouseout`.
70+
In case of fast mouse movements, intermediate elements may be ignored, but one thing we know for sure: if the pointer "officially" entered an element with `mouseover`, then upon leaving it we always get `mouseout`.
7371
```
7472
7573
## Mouseout when leaving for a child
@@ -111,7 +109,7 @@ parent.onmouseover = function(event) {
111109
};
112110
```
113111

114-
If the code inside the handlers doesn't look at `target`, then it might think that the mouse left the `parent` element, and then came back over it. But it's not the case! The mouse never left, it just moved to the child element.
112+
If we don't examine `event.target` inside the handlers, then it may seem that the mouse pointer left `parent` element, and then came back over it. But it's not the case! The mouse never left, it just moved to the child element.
115113

116114
If there's some action upon leaving the element, e.g. animation runs, then such interpretation may bring unwanted side effects.
117115

@@ -206,4 +204,4 @@ These things are good to note:
206204

207205
Events `mouseover/out` trigger even when we go from the parent element to a child element. The browser assumes that the mouse can be only over one element at one time -- the deepest one.
208206

209-
Events `mouseenter/leave` are different in that aspect: they only trigger when the mouse comes in and out the element as a whole. Also they do not bubble.
207+
Events `mouseenter/leave` are different in that aspect: they only trigger when the mouse comes in and out the element as a whole. Also they do not bubble.

0 commit comments

Comments
 (0)