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/04-object-basics/02-garbage-collection/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
@@ -207,6 +207,6 @@ A general book "The Garbage Collection Handbook: The Art of Automatic Memory Man
207
207
208
208
If you are familiar with low-level programming, the more detailed information about V8 garbage collector is in the article [A tour of V8: Garbage Collection](http://jayconrod.com/posts/55/a-tour-of-v8-garbage-collection).
209
209
210
-
[V8 blog](http://v8project.blogspot.com/) also publishes articles about changes in memory management from time to time. Naturally, to learn the garbage collection, you'd better prepare by learning about V8 internals in general and read the blog of [Vyacheslav Egorov](http://mrale.ph) who worked as one of V8 engineers. I'm saying: "V8", because it is best covered with articles in the internet. For other engines, many approaches are similar, but garbage collection differs in many aspects.
210
+
[V8 blog](https://v8.dev/) also publishes articles about changes in memory management from time to time. Naturally, to learn the garbage collection, you'd better prepare by learning about V8 internals in general and read the blog of [Vyacheslav Egorov](http://mrale.ph) who worked as one of V8 engineers. I'm saying: "V8", because it is best covered with articles in the internet. For other engines, many approaches are similar, but garbage collection differs in many aspects.
211
211
212
212
In-depth knowledge of engines is good when you need low-level optimizations. It would be wise to plan that as the next step after you're familiar with the language.
Copy file name to clipboardExpand all lines: 1-js/04-object-basics/04-object-methods/article.md
+13-9Lines changed: 13 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -63,7 +63,7 @@ user.sayHi(); // Hello!
63
63
```smart header="Object-oriented programming"
64
64
When we write our code using objects to represent entities, that's called an [object-oriented programming](https://en.wikipedia.org/wiki/Object-oriented_programming), in short: "OOP".
65
65
66
-
OOP is a big thing, an interesting science of its own. How to choose the right entities? How to organize the interaction between them? That's architecture, and there are great books on that topic, like "Design Patterns: Elements of Reusable Object-Oriented Software" by E.Gamma, R.Helm, R.Johnson, J.Vissides or "Object-Oriented Analysis and Design with Applications" by G.Booch, and more.
66
+
OOP is a big thing, an interesting science of its own. How to choose the right entities? How to organize the interaction between them? That's architecture, and there are great books on that topic, like "Design Patterns: Elements of Reusable Object-Oriented Software" by E.Gamma, R.Helm, R.Johnson, J.Vissides or "Object-Oriented Analysis and Design with Applications" by G.Booch, and more.
67
67
```
68
68
### Method shorthand
69
69
@@ -72,14 +72,14 @@ There exists a shorter syntax for methods in an object literal:
72
72
```js
73
73
// these objects do the same
74
74
75
-
letuser = {
75
+
user = {
76
76
sayHi:function() {
77
77
alert("Hello");
78
78
}
79
79
};
80
80
81
81
// method shorthand looks better, right?
82
-
letuser = {
82
+
user = {
83
83
*!*
84
84
sayHi() { // same as "sayHi: function()"
85
85
*/!*
@@ -166,7 +166,7 @@ If we used `this.name` instead of `user.name` inside the `alert`, then the code
166
166
167
167
## "this" is not bound
168
168
169
-
In JavaScript, "this" keyword behaves unlike most other programming languages. First, it can be used in any function.
169
+
In JavaScript, "this" keyword behaves unlike most other programming languages. It can be used in any function.
170
170
171
171
There's no syntax error in the code like that:
172
172
@@ -176,9 +176,9 @@ function sayHi() {
176
176
}
177
177
```
178
178
179
-
The value of `this` is evaluated during the run-time. And it can be anything.
179
+
The value of `this` is evaluated during the run-time, depending on the context. And it can be anything.
180
180
181
-
For instance, the same function may have different "this" when called from different objects:
181
+
For instance, here the same function is assigned to two different objects and has different "this" in the calls:
admin['f'](); // Admin (dot or square brackets access the method – doesn't matter)
203
203
```
204
204
205
-
Actually, we can call the function without an object at all:
205
+
The rule is simple: if `obj.f()` is called, then `this` is `obj` during the call of `f`. So it's either `user` or `admin` in the example above.
206
+
207
+
````smart header="Calling without an object: `this == undefined`"
208
+
We can even call the function without an object at all:
206
209
207
210
```js run
208
211
functionsayHi() {
@@ -216,7 +219,8 @@ In this case `this` is `undefined` in strict mode. If we try to access `this.nam
216
219
217
220
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.
218
221
219
-
Please note that usually a call of a function that uses `this` without an object is not normal, but rather a programming mistake. If a function has `this`, then it is usually meant to be called in the context of an object.
222
+
Usually such call is an programming error. If there's `this` inside a function, it expects to be called in an object context.
223
+
````
220
224
221
225
```smart header="The consequences of unbound `this`"
222
226
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.
Copy file name to clipboardExpand all lines: 1-js/05-data-types/11-json/article.md
-1Lines changed: 0 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -68,7 +68,6 @@ alert(json);
68
68
69
69
Полученная строка `json` называется *JSON-форматированным* или *сериализованным* объектом. Мы можем отправить его по сети или поместить в обычное хранилище данных.
70
70
71
-
72
71
Обратите внимание, что объект в формате JSON имеет несколько важных отличий от объектного литерала:
73
72
74
73
- Строки используют двойные кавычки. Никаких одинарных кавычек или обратных кавычек в JSON. Так `'John'` становится `"John"`.
In the loop we need to get the text inside every `li`. We can read it directly from the first child node, that is the text node:
9
+
В цикле нам нужно получить текст в каждом элементе `li`. Мы можем прочитать текстовое содержимое элемента списска из первого дочернего узла `li`, который будет текстовым узлом:
10
10
11
11
```js
12
12
for (let li ofdocument.querySelectorAll('li')) {
13
13
let title =li.firstChild.data;
14
14
15
-
// title is the text in <li> before any other nodes
15
+
//переменная title содержит текст элемента <li>
16
16
}
17
17
```
18
18
19
-
Then we can get the number of descendants `li.getElementsByTagName('li')`.
19
+
Так мы сможем получить количество потомков как `li.getElementsByTagName('li').length`.
0 commit comments