Skip to content

Commit 3085e54

Browse files
committed
Merge branch 'master' of github.com:javascript-tutorial/en.javascript.info into sync-dccca58f
2 parents 5c102c0 + dccca58 commit 3085e54

File tree

16 files changed

+69
-41
lines changed

16 files changed

+69
-41
lines changed

1-js/03-code-quality/02-coding-style/article.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ Here's an example of an `.eslintrc` file:
328328
},
329329
"rules": {
330330
"no-console": 0,
331-
"indent": ["warning", 2]
331+
"indent": 2
332332
}
333333
}
334334
```

1-js/03-code-quality/06-polyfills/article.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Actually, there are two parts in Babel:
2323

2424
2. Second, the polyfill.
2525

26-
New language features may include new built-in functions and syntax constructs.
26+
New language features may include not only syntax constructs, but also built-in functions.
2727
The transpiler rewrites the code, transforming syntax constructs into older ones. But as for new built-in functions, we need to implement them. JavaScript is a highly dynamic language, scripts may add/modify any functions, so that they behave according to the modern standard.
2828

2929
A script that updates/adds new functions is called "polyfill". It "fills in" the gap and adds missing implementations.

1-js/04-object-basics/03-garbage-collection/article.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Simply put, "reachable" values are those that are accessible or usable somehow.
2323

2424
2. Any other value is considered reachable if it's reachable from a root by a reference or by a chain of references.
2525

26-
For instance, if there's an object in a global variable, and that object has a property referencing another object, that object is considered reachable. And those that it references are also reachable. Detailed examples to follow.
26+
For instance, if there's an object in a global variable, and that object has a property referencing another object, *that* object is considered reachable. And those that it references are also reachable. Detailed examples to follow.
2727

2828
There's a background process in the JavaScript engine that is called [garbage collector](https://en.wikipedia.org/wiki/Garbage_collection_(computer_science)). It monitors all objects and removes those that have become unreachable.
2929

1-js/05-data-types/02-number/article.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ A few examples:
406406
alert( Math.pow(2, 10) ); // 2 in power 10 = 1024
407407
```
408408

409-
There are more functions and constants in `Math` object, including trigonometry, which you can find in the [docs for the Math](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Math) object.
409+
There are more functions and constants in `Math` object, including trigonometry, which you can find in the [docs for the Math object](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Math).
410410

411411
## Summary
412412

1-js/05-data-types/08-weakmap-weakset/article.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ let array = [ john ];
3030
john = null; // overwrite the reference
3131

3232
*!*
33-
// john is stored inside the array, so it won't be garbage-collected
33+
// the object previously referenced by john is stored inside the array
34+
// therefore it won't be garbage-collected
3435
// we can get it as array[0]
3536
*/!*
3637
```

1-js/08-prototypes/01-prototype-inheritance/article.md

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ In JavaScript, objects have a special hidden property `[[Prototype]]` (as named
1212

1313
![prototype](object-prototype-empty.svg)
1414

15-
The prototype is a little bit "magical". When we want to read a property from `object`, and it's missing, JavaScript automatically takes it from the prototype. In programming, such thing is called "prototypal inheritance". Many cool language features and programming techniques are based on it.
15+
When we read a property from `object`, and it's missing, JavaScript automatically takes it from the prototype. In programming, such thing is called "prototypal inheritance". And soon we'll study many examples of such inheritance, as well as cooler language features built upon it.
1616

1717
The property `[[Prototype]]` is internal and hidden, but there are many ways to set it.
1818

@@ -27,19 +27,11 @@ let rabbit = {
2727
};
2828

2929
*!*
30-
rabbit.__proto__ = animal;
30+
rabbit.__proto__ = animal; // sets rabbit.[[Prototype]] = animal
3131
*/!*
3232
```
3333

34-
```smart header="`__proto__` is a historical getter/setter for `[[Prototype]]`"
35-
Please note that `__proto__` is *not the same* as `[[Prototype]]`. It's a getter/setter for it.
36-
37-
It exists for historical reasons. In modern language it is replaced with functions `Object.getPrototypeOf/Object.setPrototypeOf` that also get/set the prototype. We'll study the reasons for that and these functions later.
38-
39-
By the specification, `__proto__` must only be supported by browsers, but in fact all environments including server-side support it. For now, as `__proto__` notation is a little bit more intuitively obvious, we'll use it in the examples.
40-
```
41-
42-
If we look for a property in `rabbit`, and it's missing, JavaScript automatically takes it from `animal`.
34+
Now if we read a property from `rabbit`, and it's missing, JavaScript will automatically take it from `animal`.
4335

4436
For instance:
4537

@@ -130,13 +122,28 @@ alert(longEar.jumps); // true (from rabbit)
130122

131123
![](proto-animal-rabbit-chain.svg)
132124

125+
Now if we read something from `longEar`, and it's missing, JavaScript will look for it in `rabbit`, and then in `animal`.
126+
133127
There are only two limitations:
134128

135129
1. The references can't go in circles. JavaScript will throw an error if we try to assign `__proto__` in a circle.
136130
2. The value of `__proto__` can be either an object or `null`. Other types are ignored.
137131

138132
Also it may be obvious, but still: there can be only one `[[Prototype]]`. An object may not inherit from two others.
139133

134+
135+
```smart header="`__proto__` is a historical getter/setter for `[[Prototype]]`"
136+
It's a common mistake of novice developers not to know the difference between these two.
137+
138+
Please note that `__proto__` is *not the same* as the internal `[[Prototype]]` property. It's a getter/setter for `[[Prototype]]`. Later we'll see situations where it matters, for now let's just keep it in mind, as we build our understanding of JavaScript language.
139+
140+
The `__proto__` property is a bit outdated. It exists for historical reasons, modern JavaScript suggests that we should use `Object.getPrototypeOf/Object.setPrototypeOf` functions instead that get/set the prototype. We'll also cover these functions later.
141+
142+
By the specification, `__proto__` must only be supported by browsers. In fact though, all environments including server-side support `__proto__`, so we're quite safe using it.
143+
144+
As the `__proto__` notation is a bit more intuitively obvious, we use it in the examples.
145+
```
146+
140147
## Writing doesn't use prototype
141148
142149
The prototype is only used for reading properties.

1-js/08-prototypes/04-prototype-methods/article.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,8 @@ alert(Object.keys(chineseDictionary)); // hello,bye
176176
Modern methods to set up and directly access the prototype are:
177177

178178
- [Object.create(proto, [descriptors])](mdn:js/Object/create) -- creates an empty object with a given `proto` as `[[Prototype]]` (can be `null`) and optional property descriptors.
179-
- [Object.getPrototypeOf(obj)](mdn:js/Object.getPrototypeOf) -- returns the `[[Prototype]]` of `obj` (same as `__proto__` getter).
180-
- [Object.setPrototypeOf(obj, proto)](mdn:js/Object.setPrototypeOf) -- sets the `[[Prototype]]` of `obj` to `proto` (same as `__proto__` setter).
179+
- [Object.getPrototypeOf(obj)](mdn:js/Object/getPrototypeOf) -- returns the `[[Prototype]]` of `obj` (same as `__proto__` getter).
180+
- [Object.setPrototypeOf(obj, proto)](mdn:js/Object/setPrototypeOf) -- sets the `[[Prototype]]` of `obj` to `proto` (same as `__proto__` setter).
181181

182182
The built-in `__proto__` getter/setter is unsafe if we'd want to put user-generated keys into an object. Just because a user may enter `"__proto__"` as the key, and there'll be an error, with hopefully light, but generally unpredictable consequences.
183183

1-js/09-classes/01-class/1-rewrite-to-class/task.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ importance: 5
44

55
# Rewrite to class
66

7-
The `Clock` class is written in functional style. Rewrite it the "class" syntax.
7+
The `Clock` class (see the sandbox) is written in functional style. Rewrite it in the "class" syntax.
88

99
P.S. The clock ticks in the console, open it to see.

1-js/09-classes/01-class/article.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ function makeClass(phrase) {
218218
return class {
219219
sayHi() {
220220
alert(phrase);
221-
};
221+
}
222222
};
223223
}
224224

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ For instance, a function call that generates the parent class:
7676
```js run
7777
function f(phrase) {
7878
return class {
79-
sayHi() { alert(phrase) }
80-
}
79+
sayHi() { alert(phrase); }
80+
};
8181
}
8282

8383
*!*
@@ -300,7 +300,7 @@ Consider this example:
300300

301301
```js run
302302
class Animal {
303-
name = 'animal'
303+
name = 'animal';
304304

305305
constructor() {
306306
alert(this.name); // (*)

0 commit comments

Comments
 (0)