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
+19-19Lines changed: 19 additions & 19 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -29,9 +29,9 @@ De exemplu:
29
29
{
30
30
// face o treabă cu variabile locale care nu ar trebui să fie văzute în exterior
31
31
32
-
let message = "Salut"; // vizibil doar în acest bloc
32
+
let message = "Bună ziua"; // vizibil doar în acest bloc
33
33
34
-
alert(message); // Salut
34
+
alert(message); // Bună ziua
35
35
}
36
36
37
37
alert(message); // Error: message is not defined
@@ -42,7 +42,7 @@ Putem folosi acest lucru pentru a izola o bucată de cod care își face propria
42
42
```js run
43
43
{
44
44
// afișează mesajul
45
-
let message ="Salut";
45
+
let message ="Bună ziua";
46
46
alert(message);
47
47
}
48
48
@@ -58,7 +58,7 @@ Vă rugăm să notați că, fără blocuri separate ar exista o eroare, dacă am
58
58
59
59
```js run
60
60
// arată mesajul
61
-
let message = "Salut";
61
+
let message = "Bună ziua";
62
62
alert(message);
63
63
64
64
// arată un alt mesaj
@@ -73,9 +73,9 @@ Pentru `if`, `for`, `while` și așa mai departe, variabilele declarate în `{..
73
73
74
74
```js run
75
75
if (true) {
76
-
let phrase ="Salut!";
76
+
let phrase ="Bună ziua!";
77
77
78
-
alert(phrase); //Salut!
78
+
alert(phrase); //Bună ziua!
79
79
}
80
80
81
81
alert(phrase); // Error, no such variable!
@@ -98,33 +98,33 @@ alert(i); // Eroare, nu există o astfel de variabilă
98
98
99
99
Vizual, `let i` se află în afara lui `{...}`. Dar construcția `for` este specială aici: variabila, declarată în interiorul ei, este considerată parte a blocului.
100
100
101
-
## Nested functions
101
+
## Funcții nested
102
102
103
-
A function is called "nested" when it is created inside another function.
103
+
O funcție este numită "nested" atunci când este creată în interiorul altei funcții.
104
104
105
-
It is easily possible to do this with JavaScript.
105
+
Acest lucru este posibil cu ușurință în JavaScript.
106
106
107
-
We can use it to organize our code, like this:
107
+
Îl putem folosi pentru a ne organiza codul, astfel:
108
108
109
109
```js
110
110
functionsayHiBye(firstName, lastName) {
111
111
112
-
// helper nested function to use below
112
+
//funcție helper nested de utilizat mai jos
113
113
functiongetFullName() {
114
114
return firstName +""+ lastName;
115
115
}
116
116
117
-
alert( "Hello, "+getFullName() );
118
-
alert( "Bye, "+getFullName() );
117
+
alert( "Bună ziua, "+getFullName() );
118
+
alert( "La revedere, "+getFullName() );
119
119
120
120
}
121
121
```
122
122
123
-
Here the*nested*function `getFullName()`is made for convenience. It can access the outer variables and so can return the full name. Nested functions are quite common in JavaScript.
123
+
Aici funcția*nested*`getFullName()`este făcută pentru conveniență. Aceasta poate accesa variabilele exterioare și astfel poate returna numele complet. Funcțiile nested sunt destul de frecvente în JavaScript.
124
124
125
-
What's much more interesting, a nested function can be returned: either as a property of a new object or as a result by itself. It can then be used somewhere else. No matter where, it still has access to the same outer variables.
125
+
Ceea ce este mult mai interesant, o funcție nested poate fi returnată: fie ca o proprietate a unui nou obiect ori ca un rezultat de sine stătător. Acesta poate fi apoi utilizat în altă parte. Indiferent unde, aceasta are în continuare acces la aceleași variabile exterioare.
126
126
127
-
Below, `makeCounter`creates the "counter" function that returns the next number on each invocation:
127
+
Mai jos, `makeCounter`creează funcția "counter" care returnează următorul număr la fiecare invocare:
128
128
129
129
```js run
130
130
functionmakeCounter() {
@@ -142,11 +142,11 @@ alert( counter() ); // 1
142
142
alert( counter() ); // 2
143
143
```
144
144
145
-
Despite being simple, slightly modified variants of that code have practical uses, for instance, as a [random number generator](https://en.wikipedia.org/wiki/Pseudorandom_number_generator)to generate random values for automated tests.
145
+
În ciuda faptului că sunt simple, variantele ușor modificate ale acestui cod au utilizări practice, de exemplu, ca [generator de numere aleatoare](https://en.wikipedia.org/wiki/Pseudorandom_number_generator)pentru a genera valori aleatoare pentru testele automate.
146
146
147
-
How does this work? If we create multiple counters, will they be independent? What's going on with the variables here?
147
+
Cum funcționează acest lucru? Dacă vom crea mai multe counters, vor fi ele independente? Ce se întâmplă cu variabilele aici?
148
148
149
-
Understanding such things is great for the overall knowledge of JavaScript and beneficial for more complex scenarios. So let's go a bit in-depth.
149
+
Înțelegerea unor astfel de lucruri este excelentă pentru cunoștințele generale despre JavaScript și benefică pentru scenarii mai complexe. Așadar haideți să aprofundăm puțin.
0 commit comments