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/06-advanced-functions/03-closure/article.md
+21-21Lines changed: 21 additions & 21 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -202,56 +202,56 @@ Totul pare simplu deocamdată, nu?
202
202
De asemenea motoarele JavaScript îl pot optimiza, pot renunța la variabilele nefolosite pentru a economisi memorie și pot efectua alte trucuri interne, atâta timp cât comportamentul vizibil rămâne cel descris.
203
203
```
204
204
205
-
### Step 2. Function Declarations
205
+
### Pasul 2. Function Declaration
206
206
207
-
A function is also a value, like a variable.
207
+
O funcție este de asemenea o valoare, la fel ca o variabilă.
208
208
209
-
**The difference is that a Function Declaration is instantly fully initialized.**
209
+
**Diferența este că o Function Declaration este instantaneu complet inițializată.**
210
210
211
-
When a Lexical Environment is created, a Function Declaration immediately becomes a ready-to-use function (unlike `let`, that is unusable till the declaration).
211
+
Atunci când este creat un Mediu Lexical, o Function Declaration devine imediat o funcție gata de utilizare (spre deosebire de `let`, care este inutilizabilă până la declarație).
212
212
213
-
That's why we can use a function, declared as Function Declaration, even before the declaration itself.
213
+
De aceea putem utiliza o funcție, declarată ca Function Declaration, chiar înainte de declarația propriu-zisă.
214
214
215
-
For example, here's the initial state of the global Lexical Environment when we add a function:
215
+
De exemplu, iată care este starea inițială a mediului lexical global atunci când adăugăm o funcție:
216
216
217
217

218
218
219
-
Naturally, this behavior only applies to Function Declarations, not Function Expressions where we assign a function to a variable, such as`let say = function(name)...`.
219
+
Firește, acest comportament se aplică numai la Function Declaration, nu și la Function Expression în care atribuim o funcție unei variabile, cum ar fi`let say = function(name)...`.
220
220
221
-
### Step 3. Inner and outer Lexical Environment
221
+
### Pasul 3. Mediul Lexical interior și exterior
222
222
223
-
When a function runs, at the beginning of the call, a new Lexical Environment is created automatically to store local variables and parameters of the call.
223
+
Atunci când rulează o funcție, la începutul apelului, se creează automat un nou mediu lexical pentru a stoca variabilele locale și parametrii apelului.
224
224
225
-
For instance, for`say("John")`, it looks like this (the execution is at the line, labelled with an arrow):
225
+
De exemplu, pentru`say("John")`, acesta arată astfel (execuția se află la linia marcată cu o săgeată):
226
226
227
227
<!--
228
228
```js
229
-
let phrase = "Hello";
229
+
let phrase = "Bună ziua";
230
230
231
231
function say(name) {
232
232
alert( `${phrase}, ${name}` );
233
233
}
234
234
235
-
say("John"); // Hello, John
235
+
say("John"); // Bună ziua, John
236
236
```-->
237
237
238
238

239
239
240
-
During the function call we have two Lexical Environments: the inner one (for the function call) and the outer one (global):
240
+
În timpul apelului funcției avem două medii lexicale: cel intern (pentru apelul funcției) și cel extern (global):
241
241
242
-
-The inner Lexical Environment corresponds to the current execution of `say`. It has a single property: `name`, the function argument. We called`say("John")`, so the value of the `name`is`"John"`.
243
-
-The outer Lexical Environment is the global Lexical Environment. It has the`phrase`variable and the function itself.
242
+
-Mediul Lexical intern corespunde execuției curente a lui `say`. Acesta are o singură proprietate: `name`, argumentul funcției. Am apelat`say("John")`, deci valoarea lui `name`este`"John"`.
243
+
-Mediul Lexical exterior este Mediul Lexical global. Acesta conține variabila`phrase`și funcția în sine.
244
244
245
-
The inner Lexical Environment has a reference to the `outer` one.
245
+
Mediul Lexical intern are o referință la cel `extern`.
246
246
247
-
**When the code wants to access a variable -- the inner Lexical Environment is searched first, then the outer one, then the more outer one and so on until the global one.**
247
+
**Când codul vrea să acceseze o variabilă -- se caută mai întâi Mediul Lexical interior, apoi cel exterior, apoi cel mai exterior și așa mai departe până la cel global.**
248
248
249
-
If a variable is not found anywhere, that's an error in strict mode (without`use strict`, an assignment to a non-existing variable creates a new global variable, for compatibility with old code).
249
+
Dacă o variabilă nu este găsită nicăieri, este o eroare în modul strict (fără`use strict`, o atribuire la o variabilă inexistentă creează o nouă variabilă globală, pentru compatibilitate cu codul vechi).
250
250
251
-
In this example the search proceeds as follows:
251
+
În acest exemplu căutarea se desfășoară după cum urmează:
252
252
253
-
-For the`name` variable, the `alert`inside`say`finds it immediately in the inner Lexical Environment.
254
-
-When it wants to access `phrase`, then there is no `phrase`locally, so it follows the reference to the outer Lexical Environment and finds it there.
253
+
-Pentru variabila`name`, `alert`din`say`o găsește imediat în Mediul Lexical intern.
254
+
-Când vrea să acceseze `phrase`, atunci nu există `phrase`la nivel local, așa că urmărește referința la Mediul Lexical exterior și o găsește acolo.
0 commit comments