Skip to content

Commit 11d3813

Browse files
authored
Merge pull request #192 from javascript-tutorial/sync-dccca58f
Sync with upstream @ dccca58
2 parents 6a929f7 + 744a1b9 commit 11d3813

File tree

16 files changed

+73
-46
lines changed

16 files changed

+73
-46
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ Se estiver a escrever várias funções "auxiliares" (*"helper" functions*) acom
270270
}
271271
```
272272
273-
3. Mista: uma função é declarada onde for empregue pela primeir vez.
273+
3. Mista: uma função é declarada onde for empregue pela primeira vez.
274274
275275
A maior parte da vezes, a segunda variante é a preferida.
276276
@@ -292,7 +292,7 @@ Algumas opções populares:
292292
- [StandardJS](https://standardjs.com/)
293293
- (e muitas mais)
294294
295-
Se for um programador iniciante, começe pela cábula (*cheatsheet*) dísponivel no início deste capítulo. Depois, poderá procurar por outros guias de estilo afim de colher mais ideias e decidir qual prefere.
295+
Se for um programador iniciante, começe pela cábula (*cheatsheet*) disponível no início deste capítulo. Depois, poderá procurar por outros guias de estilo afim de colher mais ideias e decidir qual prefere.
296296
297297
## *Linters* Automatizados
298298
@@ -329,8 +329,8 @@ Aqui está um exemplo de um ficheiro `.eslintrc`:
329329
},
330330
"rules": {
331331
"no-console": 0,
332-
},
333-
"indent": 2
332+
"indent": 2
333+
}
334334
}
335335
```
336336

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

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

2424
2. Second, the polyfill.
2525

26-
The transpiler rewrites the code, so syntax features are covered. But for new functions we need to write a special script that implements them. JavaScript is a highly dynamic language, scripts may not just add new functions, but also modify built-in ones, so that they behave according to the modern standard.
26+
New language features may include not only syntax constructs, but also built-in functions.
27+
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.
2728

2829
There's a term "polyfill" for scripts that "fill in" the gap and add missing implementations.
2930

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: 19 additions & 12 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-
That `[[Prototype]]` has a "magical" meaning. 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

@@ -131,13 +123,28 @@ alert(longEar.jumps); // true (from rabbit)
131123

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

134-
There are actually only two limitations:
126+
Now if we read something from `longEar`, and it's missing, JavaScript will look for it in `rabbit`, and then in `animal`.
127+
128+
There are only two limitations:
135129

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

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

135+
136+
```smart header="`__proto__` is a historical getter/setter for `[[Prototype]]`"
137+
It's a common mistake of novice developers not to know the difference between these two.
138+
139+
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.
140+
141+
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.
142+
143+
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.
144+
145+
As the `__proto__` notation is a bit more intuitively obvious, we use it in the examples.
146+
```
147+
141148
## Writing doesn't use prototype
142149
143150
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
@@ -175,8 +175,8 @@ alert(Object.keys(chineseDictionary)); // hello,bye
175175
Modern methods to set up and directly access the prototype are:
176176

177177
- [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.
178-
- [Object.getPrototypeOf(obj)](mdn:js/Object.getPrototypeOf) -- returns the `[[Prototype]]` of `obj` (same as `__proto__` getter).
179-
- [Object.setPrototypeOf(obj, proto)](mdn:js/Object.setPrototypeOf) -- sets the `[[Prototype]]` of `obj` to `proto` (same as `__proto__` setter).
178+
- [Object.getPrototypeOf(obj)](mdn:js/Object/getPrototypeOf) -- returns the `[[Prototype]]` of `obj` (same as `__proto__` getter).
179+
- [Object.setPrototypeOf(obj, proto)](mdn:js/Object/setPrototypeOf) -- sets the `[[Prototype]]` of `obj` to `proto` (same as `__proto__` setter).
180180

181181
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.
182182

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
@@ -221,7 +221,7 @@ function makeClass(phrase) {
221221
return class {
222222
sayHi() {
223223
alert(phrase);
224-
};
224+
}
225225
};
226226
}
227227

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)