Skip to content

Commit f6e7d39

Browse files
Merge pull request #137 from bogdanbacosca/sync-29216730
update
2 parents c99db29 + dc404de commit f6e7d39

File tree

12 files changed

+71
-97
lines changed

12 files changed

+71
-97
lines changed

1-js/04-object-basics/04-object-methods/7-calculator/task.md

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

77
Creați un obiect `calculator` cu trei metode:
88

9-
- `read()` solicită două valori și le salvează ca proprietăți ale obiectului.
9+
- `read()` solicită două valori și le salvează ca proprietăți ale obiectului cu numele `a` respectiv `b`.
1010
- `sum()` returnează suma valorilor salvate.
1111
- `mul()` multiplică valorile salvate și returnează rezultatul.
1212

1-js/04-object-basics/04-object-methods/8-chain-calls/solution.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ let ladder = {
2323
}
2424
};
2525

26-
ladder.up().up().down().showStep().down().showStep(); // shows 1 then 0
26+
ladder.up().up().down().showStep().down().showStep(); // arată 1 apoi 0
2727
```
2828

29-
De asemenea, putem scrie câte o apelare pe linie. Pentru înlănțuirile lungi este mai lizibil:
29+
De asemenea putem scrie câte o singură apelare pe linie. Pentru înlănțuirile lungi este mai lizibil:
3030

3131
```js
3232
ladder

1-js/04-object-basics/04-object-methods/article.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ OOP este un lucru mare, o știință interesantă în sine. Cum să alegi entit
7070
Există o sintaxă mai scurtă pentru metode într-un obiect literal:
7171

7272
```js
73-
// aceste obiecte realizează același lucru
73+
// aceste obiecte fac același lucru
7474

7575
user = {
7676
sayHi: function() {
@@ -90,7 +90,7 @@ user = {
9090

9191
După cum s-a demonstrat, putem omite `"function"` și scriem doar `sayHi()`.
9292

93-
În realitate, notațiile nu sunt complet identice. Există diferențe subtile legate de moștenirea obiectelor (care vor fi acoperite ulterior), dar deocamdată nu contează. În aproape toate cazurile, se preferă sintaxa mai scurtă.
93+
Să spunem adevărul, notațiile nu sunt complet identice. Există diferențe subtile legate de moștenirea obiectelor (care vor fi acoperite ulterior), dar deocamdată nu contează. În aproape toate cazurile, se preferă sintaxa mai scurtă.
9494

9595
## "this" în metode
9696

1-js/04-object-basics/08-symbol/article.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ alert(id.toString()); // Symbol(id), acum funcționează
7070
```
7171
7272
Sau să obținem proprietatea `symbol.description` pentru a afișa numai descrierea:
73+
7374
```js run
7475
let id = Symbol("id");
7576
*!*
@@ -172,7 +173,7 @@ alert( "Direct: " + user[id] ); // Direct: 123
172173

173174
[Object.keys(user)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys) le ignoră, de asemenea. Aceasta este o parte a principiului general "ascunderea proprietăților simbolice". Dacă un alt script sau librărie iterează asupra obiectului nostru, nu va accesa neașteptat o proprietate simbol.
174175

175-
În contrast, metoda [Object.assign](mdn:js/Object/assign) copiază proprietățile de ambele tipuri, șir și simbol:
176+
În contrast, metoda [Object.assign](mdn:js/Object/assign) copiază atât proprietățile string cât și symbol:
176177

177178
```js run
178179
let id = Symbol("id");
@@ -185,7 +186,7 @@ let clone = Object.assign({}, user);
185186
alert( clone[id] ); // 123
186187
```
187188

188-
Nu este niciun paradox aici. Așa este construit. Ideea este că, atunci când clonăm un obiect sau contopim obiecte, în mod normal vrem ca *toate* proprietățile să fie copiate (incluzând simboluri precum `id`).
189+
Nu este niciun paradox aici. Așa este construit. Ideea este că, atunci când clonăm un obiect sau contopim obiecte, de obicei vrem ca *toate* proprietățile să fie copiate (incluzând simboluri precum `id`).
189190

190191
## Simboluri globale
191192

@@ -284,4 +285,4 @@ Simbolurile au două cazuri principale de folosire:
284285

285286
2. Există multe simboluri sistem folosite de JavaScript care sunt accesibile prin `Symbol.*`. Le putem folosi pentru a altera câteva comportamente incluse în limbaj. De exemplu, mai târziu în tutorial vom folosi `Symbol.iterator` pentru [iterabile](info:iterable), `Symbol.toPrimitive` pentru a configura [conversia object-to-primitive](info:object-toprimitive) ș.a.m.d.
286287

287-
Tehnic, simbolurile nu sunt 100% ascunse. Există metode ale limbajului JavaScript [Object.getOwnPropertySymbols(obj)](mdn:js/Object/getOwnPropertySymbols) care ne permit sa accesăm toate simbolurile. Mai există o metodă numită [Reflect.ownKeys(obj)](mdn:js/Reflect/ownKeys) care returnează *toate* cheile unui obiect incluzându-le și pe cele simbolice. Dar cele mai multe librării, funcții built-in și construcții de sintaxă nu folosesc aceste metode.
288+
Tehnic, simbolurile nu sunt 100% ascunse. Există o metodă built-in [Object.getOwnPropertySymbols(obj)](mdn:js/Object/getOwnPropertySymbols) care ne permit sa accesăm toate simbolurile. Mai există o metodă numită [Reflect.ownKeys(obj)](mdn:js/Reflect/ownKeys) care returnează *toate* cheile unui obiect incluzându-le și pe cele simbolice. Dar cele mai multe librării, funcții built-in și construcții de sintaxă nu folosesc aceste metode.

1-js/06-advanced-functions/03-closure/article.md

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ We already know that a function can access variables outside of it ("outer" vari
77

88
But what happens if outer variables change since a function is created? Will the function get newer values or the old ones?
99

10-
And what if a function is passed along as a parameter and called from another place of code, will it get access to outer variables at the new place?
10+
And what if a function is passed along as an argument and called from another place of code, will it get access to outer variables at the new place?
1111

1212
Let's expand our knowledge to understand these scenarios and more complex ones.
1313

@@ -173,17 +173,7 @@ In this simple code without functions, there is only one Lexical Environment:
173173

174174
![lexical environment](lexical-environment-global.svg)
175175

176-
<<<<<<< HEAD
177-
<<<<<<< HEAD
178-
5. When the `counter()` is called, an "empty" Lexical Environment is created for it. It has no local variables by itself. But the `[[Environment]]` of `counter` is used as the outer reference for it, so it has access to the variables of the former `makeCounter()` call where it was created:
179-
180-
![](lexenv-nested-makecounter-5.svg)
181-
=======
182-
5. When `counter()` is called, a new Lexical Environment is created for the call. It's empty, as `counter` has no local variables by itself. But the `[[Environment]]` of `counter` is used as the `outer` reference for it, that provides access to the variables of the former `makeCounter()` call where it was created:
183-
>>>>>>> 852ee189170d9022f67ab6d387aeae76810b5923
184-
=======
185176
This is the so-called *global* Lexical Environment, associated with the whole script.
186-
>>>>>>> 29216730a877be28d0a75a459676db6e7f5c4834
187177

188178
On the picture above, the rectangle means Environment Record (variable store) and the arrow means the outer reference. The global Lexical Environment has no outer reference, that's why the arrow points to `null`.
189179

@@ -195,20 +185,11 @@ Here's a little bit longer code:
195185

196186
Rectangles on the right-hand side demonstrate how the global Lexical Environment changes during the execution:
197187

198-
<<<<<<< HEAD
199-
![](lexenv-nested-makecounter-6.svg)
200-
<<<<<<< HEAD
201-
202-
So we return to the previous step with the only change -- the new value of `count`. The following calls all do the same.
203-
=======
204-
>>>>>>> 852ee189170d9022f67ab6d387aeae76810b5923
205-
=======
206188
1. When the script starts, the Lexical Environment is pre-populated with all declared variables.
207189
- Initially, they are in the "Uninitialized" state. That's a special internal state, it means that the engine knows about the variable, but it cannot be referenced until it has been declared with `let`. It's almost the same as if the variable didn't exist.
208190
2. Then `let phrase` definition appears. There's no assignment yet, so its value is `undefined`. We can use the variable from this point forward.
209191
3. `phrase` is assigned a value.
210192
4. `phrase` changes the value.
211-
>>>>>>> 29216730a877be28d0a75a459676db6e7f5c4834
212193

213194
Everything looks simple for now, right?
214195

1-js/11-async/02-promise-basics/article.md

Lines changed: 49 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,10 @@ When the executor obtains the result, be it soon or late, doesn't matter, it sho
3333

3434
So to summarize: the executor runs automatically and attempts to perform a job. When it is finished with the attempt, it calls `resolve` if it was successful or `reject` if there was an error.
3535

36-
<<<<<<< HEAD
37-
<<<<<<< HEAD
38-
![](promise-resolve-reject.svg)
39-
=======
40-
The `promise` object returned by `new Promise` constructor has internal properties:
41-
>>>>>>> 852ee189170d9022f67ab6d387aeae76810b5923
42-
=======
4336
The `promise` object returned by the `new Promise` constructor has these internal properties:
44-
>>>>>>> 29216730a877be28d0a75a459676db6e7f5c4834
4537

4638
- `state` — initially `"pending"`, then changes to either `"fulfilled"` when `resolve` is called or `"rejected"` when `reject` is called.
47-
- `result` — initially `undefined`, then changes to `value` when `resolve(value)` called or `error` when `reject(error)` is called.
39+
- `result` — initially `undefined`, then changes to `value` when `resolve(value)` is called or `error` when `reject(error)` is called.
4840

4941
So the executor eventually moves `promise` to one of these states:
5042

@@ -68,7 +60,7 @@ We can see two things by running the code above:
6860
1. The executor is called automatically and immediately (by `new Promise`).
6961
2. The executor receives two arguments: `resolve` and `reject`. These functions are pre-defined by the JavaScript engine, so we don't need to create them. We should only call one of them when ready.
7062

71-
After one second of "processing" the executor calls `resolve("done")` to produce the result. This changes the state of the `promise` object:
63+
After one second of "processing", the executor calls `resolve("done")` to produce the result. This changes the state of the `promise` object:
7264

7365
![](promise-resolve-1.svg)
7466

@@ -135,9 +127,9 @@ That's fine. We immediately have a resolved promise.
135127
The properties `state` and `result` of the Promise object are internal. We can't directly access them. We can use the methods `.then`/`.catch`/`.finally` for that. They are described below.
136128
```
137129
138-
## Consumers: then, catch, finally
130+
## Consumers: then, catch
139131
140-
A Promise object serves as a link between the executor (the "producing code" or "singer") and the consuming functions (the "fans"), which will receive the result or error. Consuming functions can be registered (subscribed) using methods `.then`, `.catch` and `.finally`.
132+
A Promise object serves as a link between the executor (the "producing code" or "singer") and the consuming functions (the "fans"), which will receive the result or error. Consuming functions can be registered (subscribed) using the methods `.then` and `.catch`.
141133
142134
### then
143135
@@ -152,9 +144,9 @@ promise.then(
152144
);
153145
```
154146
155-
The first argument of `.then` is a function that runs when the promise is resolved, and receives the result.
147+
The first argument of `.then` is a function that runs when the promise is resolved and receives the result.
156148
157-
The second argument of `.then` is a function that runs when the promise is rejected, and receives the error.
149+
The second argument of `.then` is a function that runs when the promise is rejected and receives the error.
158150
159151
For instance, here's a reaction to a successfully resolved promise:
160152
@@ -220,59 +212,83 @@ promise.catch(alert); // shows "Error: Whoops!" after 1 second
220212
221213
The call `.catch(f)` is a complete analog of `.then(null, f)`, it's just a shorthand.
222214
223-
### finally
215+
## Cleanup: finally
224216
225217
Just like there's a `finally` clause in a regular `try {...} catch {...}`, there's `finally` in promises.
226218
227-
The call `.finally(f)` is similar to `.then(f, f)` in the sense that `f` always runs when the promise is settled: be it resolve or reject.
219+
The call `.finally(f)` is similar to `.then(f, f)` in the sense that `f` runs always, when the promise is settled: be it resolve or reject.
220+
221+
The idea of `finally` is to set up a handler for performing cleanup/finalizing after the previous operations are complete.
228222
229-
`finally` is a good handler for performing cleanup, e.g. stopping our loading indicators, as they are not needed anymore, no matter what the outcome is.
223+
E.g. stopping loading indicators, closing no longer needed connections, etc.
230224
231-
Like this:
225+
Think of it as a party finisher. No matter was a party good or bad, how many friends were in it, we still need (or at least should) do a cleanup after it.
226+
227+
The code may look like this:
232228
233229
```js
234230
new Promise((resolve, reject) => {
235-
/* do something that takes time, and then call resolve/reject */
231+
/* do something that takes time, and then call resolve or maybe reject */
236232
})
237233
*!*
238234
// runs when the promise is settled, doesn't matter successfully or not
239235
.finally(() => stop loading indicator)
240-
// so the loading indicator is always stopped before we process the result/error
236+
// so the loading indicator is always stopped before we go on
241237
*/!*
242238
.then(result => show result, err => show error)
243239
```
244240
245-
That said, `finally(f)` isn't exactly an alias of `then(f,f)` though. There are few subtle differences:
241+
Please note that `finally(f)` isn't exactly an alias of `then(f,f)` though.
242+
243+
There are important differences:
246244
247245
1. A `finally` handler has no arguments. In `finally` we don't know whether the promise is successful or not. That's all right, as our task is usually to perform "general" finalizing procedures.
248-
2. A `finally` handler passes through results and errors to the next handler.
246+
247+
Please take a look at the example above: as you can see, the `finally` handler has no arguments, and the promise outcome is handled by the next handler.
248+
2. A `finally` handler "passes through" the result or error to the next suitable handler.
249249
250250
For instance, here the result is passed through `finally` to `then`:
251+
251252
```js run
252253
new Promise((resolve, reject) => {
253-
setTimeout(() => resolve("result"), 2000)
254+
setTimeout(() => resolve("value"), 2000);
254255
})
255-
.finally(() => alert("Promise ready"))
256-
.then(result => alert(result)); // <-- .then handles the result
256+
.finally(() => alert("Promise ready")) // triggers first
257+
.then(result => alert(result)); // <-- .then shows "value"
257258
```
258259
259-
And here there's an error in the promise, passed through `finally` to `catch`:
260+
As you can see, the `value` returned by the first promise is passed through `finally` to the next `then`.
261+
262+
That's very convenient, because `finally` is not meant to process a promise result. As said, it's a place to do generic cleanup, no matter what the outcome was.
263+
264+
And here's an example of an error, for us to see how it's passed through `finally` to `catch`:
260265
261266
```js run
262267
new Promise((resolve, reject) => {
263268
throw new Error("error");
264269
})
265-
.finally(() => alert("Promise ready"))
266-
.catch(err => alert(err)); // <-- .catch handles the error object
270+
.finally(() => alert("Promise ready")) // triggers first
271+
.catch(err => alert(err)); // <-- .catch shows the error
267272
```
268273
269-
That's very convenient, because `finally` is not meant to process a promise result. So it passes it through.
274+
3. A `finally` handler also shouldn't return anything. If it does, the returned value is silently ignored.
270275
271-
We'll talk more about promise chaining and result-passing between handlers in the next chapter.
276+
The only exception to this rule is when a `finally` handler throws an error. Then this error goes to the next handler, instead of any previous outcome.
272277
278+
To summarize:
279+
280+
- A `finally` handler doesn't get the outcome of the previous handler (it has no arguments). This outcome is passed through instead, to the next suitable handler.
281+
- If a `finally` handler returns something, it's ignored.
282+
- When `finally` throws an error, then the execution goes to the nearest error handler.
283+
284+
These features are helpful and make things work just the right way if we use `finally` how it's supposed to be used: for generic cleanup procedures.
273285
274286
````smart header="We can attach handlers to settled promises"
275-
If a promise is pending, `.then/catch/finally` handlers wait for it. Otherwise, if a promise has already settled, they just run:
287+
If a promise is pending, `.then/catch/finally` handlers wait for its outcome.
288+
289+
Sometimes, it might be that a promise is already settled when we add a handler to it.
290+
291+
In such case, these handlers just run immediately:
276292
277293
```js run
278294
// the promise becomes resolved immediately upon creation
@@ -286,10 +302,10 @@ Note that this makes promises more powerful than the real life "subscription lis
286302
Promises are more flexible. We can add handlers any time: if the result is already there, they just execute.
287303
````
288304

289-
Next, let's see more practical examples of how promises can help us write asynchronous code.
290-
291305
## Example: loadScript [#loadscript]
292306

307+
Next, let's see more practical examples of how promises can help us write asynchronous code.
308+
293309
We've got the `loadScript` function for loading a script from the previous chapter.
294310

295311
Here's the callback-based variant, just to remind us of it:

1-js/99-js-misc/01-proxy/article.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -730,11 +730,7 @@ The problem is actually in the proxy, in the line `(*)`.
730730
2. The prototype is `userProxy`.
731731
3. When reading `name` property from the proxy, its `get` trap triggers and returns it from the original object as `target[prop]` in the line `(*)`.
732732

733-
<<<<<<< HEAD
734-
![](proxy-inherit.svg)
735-
=======
736733
A call to `target[prop]`, when `prop` is a getter, runs its code in the context `this=target`. So the result is `this._name` from the original object `target`, that is: from `user`.
737-
>>>>>>> 852ee189170d9022f67ab6d387aeae76810b5923
738734

739735
To fix such situations, we need `receiver`, the third argument of `get` trap. It keeps the correct `this` to be passed to a getter. In our case that's `admin`.
740736

1-js/99-js-misc/04-reference-type/2-check-syntax/solution.md

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,7 @@ let user = {
1111
(user.go)() // eroare!
1212
```
1313

14-
<<<<<<< HEAD:1-js/04-object-basics/04-object-methods/2-check-syntax/solution.md
15-
Din mesajul de eroare furnizat de majoritatea browserelor nu reiese ce a mers prost.
16-
=======
17-
The error message in most browsers does not give us much of a clue about what went wrong.
18-
>>>>>>> 29216730a877be28d0a75a459676db6e7f5c4834:1-js/99-js-misc/04-reference-type/2-check-syntax/solution.md
14+
Mesajul de eroare din majoritatea browserelor nu ne oferă prea multe indicii despre ce a mers greșit.
1915

2016
**Eroarea apare deoarece simbolul ";" lipsește după `user = {...}`.**
2117

@@ -38,8 +34,5 @@ let user = {
3834
(user.go)() // John
3935
```
4036

41-
<<<<<<< HEAD:1-js/04-object-basics/04-object-methods/2-check-syntax/solution.md
42-
Rețineți că parantezele din jurul `(user.go)` nu fac nimic aici. De obicei setează ordinea operațiilor, dar aici punctul `.` are oricum precedență, deci nu are niciun efect. Singurul lucru care contează este simbolul ";".
43-
=======
44-
Please note that parentheses around `(user.go)` do nothing here. Usually they setup the order of operations, but here the dot `.` works first anyway, so there's no effect. Only the semicolon thing matters.
45-
>>>>>>> 29216730a877be28d0a75a459676db6e7f5c4834:1-js/99-js-misc/04-reference-type/2-check-syntax/solution.md
37+
Vă rugăm să rețineți că parantezele din jurul `(user.go)` nu fac nimic aici. De obicei ele stabilesc ordinea operațiilor, dar aici punctul `.` funcționează primul oricum, deci nu au niciun efect. Doar chestia cu punctul și virgula contează.
38+

1-js/99-js-misc/04-reference-type/2-check-syntax/task.md

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

55
# Verificare de sintaxă
66

7-
Care este rezultatul următorului cod?
7+
Care este rezultatul acestui cod?
88

99

1010
```js no-beautify

0 commit comments

Comments
 (0)