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
+4-4Lines changed: 4 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -156,7 +156,7 @@ The following "garbage collection" steps are regularly performed:
156
156
- The garbage collector takes roots and "marks" (remembers) them.
157
157
- Then it visits and "marks" all references from them.
158
158
- Then it visits marked objects and marks *their* references. All visited objects are remembered, so as not to visit the same object twice in the future.
159
-
- ...And so on until there are unvisited references (reachable from the roots).
159
+
- ...And so on until every reachable (from the roots) references are visited.
160
160
- All objects except marked ones are removed.
161
161
162
162
For instance, let our object structure look like this:
@@ -181,17 +181,17 @@ Now the objects that could not be visited in the process are considered unreacha
181
181
182
182

183
183
184
-
That's the concept of how garbage collection works.
184
+
We can also imagine the process as spilling a huge bucket of paint from the roots, that flows through all references and marks all reachable objects. The unmarked ones are then removed.
185
185
186
-
JavaScript engines apply many optimizations to make it run faster and not affect the execution.
186
+
That's the concept of how garbage collection works. JavaScript engines apply many optimizations to make it run faster and not affect the execution.
187
187
188
188
Some of the optimizations:
189
189
190
190
-**Generational collection** -- objects are split into two sets: "new ones" and "old ones". Many objects appear, do their job and die fast, they can be cleaned up aggressively. Those that survive for long enough, become "old" and are examined less often.
191
191
-**Incremental collection** -- if there are many objects, and we try to walk and mark the whole object set at once, it may take some time and introduce visible delays in the execution. So the engine tries to split the garbage collection into pieces. Then the pieces are executed one by one, separately. That requires some extra bookkeeping between them to track changes, but we have many tiny delays instead of a big one.
192
192
-**Idle-time collection** -- the garbage collector tries to run only while the CPU is idle, to reduce the possible effect on the execution.
193
193
194
-
There are other optimizations and flavours of garbage collection algorithms. As much as I'd like to describe them here, I have to hold off, because different engines implement different tweaks and techniques. And, what's even more important, things change as engines develop, so going deeper "in advance", without a real need is probably not worth that. Unless, of course, it is a matter of pure interest, then there will be some links for you below.
194
+
There exist other optimizations and flavours of garbage collection algorithms. As much as I'd like to describe them here, I have to hold off, because different engines implement different tweaks and techniques. And, what's even more important, things change as engines develop, so studying deeper "in advance", without a real need is probably not worth that. Unless, of course, it is a matter of pure interest, then there will be some links for you below.
Copy file name to clipboardExpand all lines: 1-js/05-data-types/09-keys-values-entries/article.md
+1-3Lines changed: 1 addition & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -99,6 +99,4 @@ let doublePrices = Object.fromEntries(
99
99
alert(doublePrices.meat); // 8
100
100
```
101
101
102
-
It may look difficult from the first sight, but becomes easy to understand after you use it once or twice.
103
-
104
-
We can make powerful one-liners for more complex transforms this way. It's only important to keep balance, so that the code is still simple enough to understand it.
102
+
It may look difficult from the first sight, but becomes easy to understand after you use it once or twice. We can make powerful chains of transforms this way.
Copy file name to clipboardExpand all lines: 1-js/06-advanced-functions/01-recursion/article.md
+7-1Lines changed: 7 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -185,7 +185,13 @@ Here's the context stack when we entered the subcall `pow(2, 2)`:
185
185
186
186
The new current execution context is on top (and bold), and previous remembered contexts are below.
187
187
188
-
When we finish the subcall -- it is easy to resume the previous context, because it keeps both variables and the exact place of the code where it stopped. Here in the picture we use the word "line", but of course it's more precise.
188
+
When we finish the subcall -- it is easy to resume the previous context, because it keeps both variables and the exact place of the code where it stopped.
189
+
190
+
```smart
191
+
Here in the picture we use the word "line", as our example there's only one subcall in line, but generally a single line of code may contain multiple subcalls, like `pow(…) + pow(…) + somethingElse(…)`.
192
+
193
+
So it would be more precise to say that the execution resumes "immediately after the subcall".
Copy file name to clipboardExpand all lines: 1-js/08-prototypes/03-native-prototypes/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
@@ -193,4 +193,4 @@ Borrowing methods is flexible, it allows to mix functionality from different obj
193
193
- The methods are stored in the prototype (`Array.prototype`, `Object.prototype`, `Date.prototype` etc).
194
194
- The object itself stores only the data (array items, object properties, the date).
195
195
- Primitives also store methods in prototypes of wrapper objects: `Number.prototype`, `String.prototype`, `Boolean.prototype`. Only `undefined` and `null` do not have wrapper objects.
196
-
- Built-in prototypes can be modified or populated with new methods. But it's not recommended to change them. Probably the only allowable cause is when we add-in a new standard, but not yet supported by the engine JavaScript method.
196
+
- Built-in prototypes can be modified or populated with new methods. But it's not recommended to change them. Probably the only allowable case is when we add-in a new standard, but not yet supported by the engine JavaScript method.
- The `"prototype"` property of a constructor function works since very ancient times.
75
-
- Later, in the year 2012:`Object.create` appeared in the standard. It gave the ability to create objects with a given prototype, but did not provide the ability to get/set it. So browsers implemented the non-standard `__proto__` accessor that allowed the user to get/set a prototype at any time.
76
-
- Later, in the year 2015:`Object.setPrototypeOf` and `Object.getPrototypeOf` were added to the standard, to perform the same functionality as `__proto__`. As `__proto__` was de-facto implemented everywhere, it was kind-of deprecated and made its way to the Annex B of the standard, that is: optional for non-browser environments.
74
+
- The `"prototype"` property of a constructor function has worked since very ancient times.
75
+
- Later, in the year 2012,`Object.create` appeared in the standard. It gave the ability to create objects with a given prototype, but did not provide the ability to get/set it. So browsers implemented the non-standard `__proto__` accessor that allowed the user to get/set a prototype at any time.
76
+
- Later, in the year 2015,`Object.setPrototypeOf` and `Object.getPrototypeOf` were added to the standard, to perform the same functionality as `__proto__`. As `__proto__` was de-facto implemented everywhere, it was kind-of deprecated and made its way to the Annex B of the standard, that is: optional for non-browser environments.
Copy file name to clipboardExpand all lines: 1-js/09-classes/01-class/article.md
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -89,7 +89,7 @@ What `class User {...}` construct really does is:
89
89
1. Creates a function named `User`, that becomes the result of the class declaration. The function code is taken from the `constructor` method (assumed empty if we don't write such method).
90
90
2. Stores class methods, such as `sayHi`, in `User.prototype`.
91
91
92
-
Afterwards, for `new User`objects, when we call a method, it's taken from the prototype, just as described in the chapter <info:function-prototype>. So the object has access to class methods.
92
+
After `new User`object is created, when we call its method, it's taken from the prototype, just as described in the chapter <info:function-prototype>. So the object has access to class methods.
93
93
94
94
We can illustrate the result of `class User` declaration as:
95
95
@@ -142,11 +142,11 @@ user.sayHi();
142
142
143
143
The result of this definition is about the same. So, there are indeed reasons why `class` can be considered a syntax sugar to define a constructor together with its prototype methods.
144
144
145
-
Although, there are important differences.
145
+
Still, there are important differences.
146
146
147
147
1. First, a function created by `class` is labelled by a special internal property `[[FunctionKind]]:"classConstructor"`. So it's not entirely the same as creating it manually.
148
148
149
-
Unlike a regular function, a class constructor must be called with `new`:
149
+
And unlike a regular function, a class constructor must be called with `new`:
Copy file name to clipboardExpand all lines: 1-js/09-classes/02-class-inheritance/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
@@ -131,7 +131,7 @@ class Rabbit extends Animal {
131
131
}
132
132
```
133
133
134
-
...But usually we don't want to totally replace a parent method, but rather to build on top of it, tweak or extend its functionality. We do something in our method, but call the parent method before/after it or in the process.
134
+
...But usually we don't want to totally replace a parent method, but rather to build on top of it to tweak or extend its functionality. We do something in our method, but call the parent method before/after it or in the process.
0 commit comments