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/03-code-quality/02-coding-style/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
@@ -270,7 +270,7 @@ Se estiver a escrever várias funções "auxiliares" (*"helper" functions*) acom
270
270
}
271
271
```
272
272
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.
274
274
275
275
A maior parte da vezes, a segunda variante é a preferida.
276
276
@@ -292,7 +292,7 @@ Algumas opções populares:
292
292
- [StandardJS](https://standardjs.com/)
293
293
- (e muitas mais)
294
294
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.
296
296
297
297
## *Linters* Automatizados
298
298
@@ -329,8 +329,8 @@ Aqui está um exemplo de um ficheiro `.eslintrc`:
Copy file name to clipboardExpand all lines: 1-js/03-code-quality/06-polyfills/article.md
+2-1Lines changed: 2 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -23,7 +23,8 @@ Actually, there are two parts in Babel:
23
23
24
24
2. Second, the polyfill.
25
25
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.
27
28
28
29
There's a term "polyfill" for scripts that "fill in" the gap and add missing implementations.
Copy file name to clipboardExpand all lines: 1-js/04-object-basics/03-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
@@ -23,7 +23,7 @@ Simply put, "reachable" values are those that are accessible or usable somehow.
23
23
24
24
2. Any other value is considered reachable if it's reachable from a root by a reference or by a chain of references.
25
25
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.
27
27
28
28
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.
Copy file name to clipboardExpand all lines: 1-js/05-data-types/02-number/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
@@ -406,7 +406,7 @@ A few examples:
406
406
alert( Math.pow(2, 10) ); // 2 in power 10 = 1024
407
407
```
408
408
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).
Copy file name to clipboardExpand all lines: 1-js/08-prototypes/01-prototype-inheritance/article.md
+19-12Lines changed: 19 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,7 +12,7 @@ In JavaScript, objects have a special hidden property `[[Prototype]]` (as named
12
12
13
13

14
14
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.
16
16
17
17
The property `[[Prototype]]` is internal and hidden, but there are many ways to set it.
```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`.
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:
135
129
136
130
1. The references can't go in circles. JavaScript will throw an error if we try to assign `__proto__` in a circle.
137
131
2. The value of `__proto__` can be either an object or `null`, other types (like primitives) are ignored.
138
132
139
133
Also it may be obvious, but still: there can be only one `[[Prototype]]`. An object may not inherit from two others.
140
134
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
+
141
148
## Writing doesn't use prototype
142
149
143
150
The prototype is only used for reading properties.
Modern methods to set up and directly access the prototype are:
176
176
177
177
-[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).
180
180
181
181
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.
0 commit comments