Skip to content

Commit 9e856c2

Browse files
committed
translated until line 334
1 parent 82abe8f commit 9e856c2

File tree

1 file changed

+35
-35
lines changed
  • 1-js/06-advanced-functions/06-function-object

1 file changed

+35
-35
lines changed

1-js/06-advanced-functions/06-function-object/article.md

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -207,68 +207,68 @@ Așadar alegerea implementării depinde de obiectivele noastre.
207207

208208
## Named Function Expression
209209

210-
Named Function Expression, or NFE, is a term for Function Expressions that have a name.
210+
Named Function Expression, sau NFE, este un termen pentru Function Expressions care au un nume.
211211

212-
For instance, let's take an ordinary Function Expression:
212+
De exemplu, să luăm o Function Expression obișnuită:
213213

214214
```js
215215
let sayHi = function(who) {
216216
alert(`Hello, ${who}`);
217217
};
218218
```
219219

220-
And add a name to it:
220+
Și adăugați-i un nume:
221221

222222
```js
223223
let sayHi = function *!*func*/!*(who) {
224-
alert(`Hello, ${who}`);
224+
alert(`Bună ziua, ${who}`);
225225
};
226226
```
227227

228-
Did we achieve anything here? What's the purpose of that additional `"func"` name?
228+
Am realizat ceva aici? Care este scopul acelui nume suplimentar `"func"`?
229229

230-
First let's note, that we still have a Function Expression. Adding the name `"func"` after `function` did not make it a Function Declaration, because it is still created as a part of an assignment expression.
230+
În primul rând, să notăm că avem încă o Function Expression. Adăugarea numelui `"func"` după `function` nu a făcut-o Function Declaration, deoarece aceasta este încă creată ca parte a unei expresii de atribuire.
231231

232-
Adding such a name also did not break anything.
232+
De asemenea adăugarea unui astfel de nume nu a stricat nimic.
233233

234-
The function is still available as `sayHi()`:
234+
Funcția este în continuare disponibilă ca `sayHi()`:
235235

236236
```js run
237237
let sayHi = function *!*func*/!*(who) {
238-
alert(`Hello, ${who}`);
238+
alert(`Bună ziua, ${who}`);
239239
};
240240

241-
sayHi("John"); // Hello, John
241+
sayHi("John"); // Bună ziua, John
242242
```
243243

244-
There are two special things about the name `func`, that are the reasons for it:
244+
Există două lucruri speciale în legătură cu numele `func`, care sunt motivele pentru acesta:
245245

246-
1. It allows the function to reference itself internally.
247-
2. It is not visible outside of the function.
246+
1. Acesta permite funcției să facă referire la ea însăși în mod intern.
247+
2. Nu este vizibil în afara funcției.
248248

249-
For instance, the function `sayHi` below calls itself again with `"Guest"` if no `who` is provided:
249+
De exemplu, funcția `sayHi` de mai jos se apelează din nou pe sine cu `"Guest"` dacă nu este furnizat `who`:
250250

251251
```js run
252252
let sayHi = function *!*func*/!*(who) {
253253
if (who) {
254-
alert(`Hello, ${who}`);
254+
alert(`Bună ziua, ${who}`);
255255
} else {
256256
*!*
257-
func("Guest"); // use func to re-call itself
257+
func("Guest"); // folosește func pentru a se re-apela pe sine însăși
258258
*/!*
259259
}
260260
};
261261

262-
sayHi(); // Hello, Guest
262+
sayHi(); // Bună ziua, Guest
263263

264-
// But this won't work:
265-
func(); // Error, func is not defined (not visible outside of the function)
264+
// Dar acest lucru nu va funcționa:
265+
func(); // Error, func is not defined (nu este vizibil în afara funcției)
266266
```
267267

268-
Why do we use `func`? Maybe just use `sayHi` for the nested call?
268+
De ce folosim `func`? Poate doar să folosim `sayHi` pentru apelul nested?
269269

270270

271-
Actually, in most cases we can:
271+
De fapt, în majoritatea cazurilor putem:
272272

273273
```js
274274
let sayHi = function(who) {
@@ -282,12 +282,12 @@ let sayHi = function(who) {
282282
};
283283
```
284284

285-
The problem with that code is that `sayHi` may change in the outer code. If the function gets assigned to another variable instead, the code will start to give errors:
285+
Problema cu acel cod este că `sayHi` se poate schimba în codul exterior. Dacă în schimb funcția este atribuită unei alte variabile, codul va începe să dea erori:
286286

287287
```js run
288288
let sayHi = function(who) {
289289
if (who) {
290-
alert(`Hello, ${who}`);
290+
alert(`Bună ziua, ${who}`);
291291
} else {
292292
*!*
293293
sayHi("Guest"); // Error: sayHi is not a function
@@ -298,40 +298,40 @@ let sayHi = function(who) {
298298
let welcome = sayHi;
299299
sayHi = null;
300300

301-
welcome(); // Error, the nested sayHi call doesn't work any more!
301+
welcome(); // Eroare, apelul nested sayHi nu mai funcționează!
302302
```
303303

304-
That happens because the function takes `sayHi` from its outer lexical environment. There's no local `sayHi`, so the outer variable is used. And at the moment of the call that outer `sayHi` is `null`.
304+
Asta se întâmplă deoarece funcția preia `sayHi` din mediul său lexical extern. Nu există un `sayHi` local, așa că se folosește variabila exterioară. Iar în momentul apelului, acea `sayHi` exterioară este `null`.
305305

306-
The optional name which we can put into the Function Expression is meant to solve exactly these kinds of problems.
306+
Numele opțional pe care îl putem pune în Function Expression este menit să rezolve exact acest tip de probleme.
307307

308-
Let's use it to fix our code:
308+
Să-l folosim pentru a ne corecta codul:
309309

310310
```js run
311311
let sayHi = function *!*func*/!*(who) {
312312
if (who) {
313-
alert(`Hello, ${who}`);
313+
alert(`Bună ziua, ${who}`);
314314
} else {
315315
*!*
316-
func("Guest"); // Now all fine
316+
func("Guest"); // Acum totul este în regulă
317317
*/!*
318318
}
319319
};
320320

321321
let welcome = sayHi;
322322
sayHi = null;
323323

324-
welcome(); // Hello, Guest (nested call works)
324+
welcome(); // Bună ziua, Guest (apelul nested funcționează)
325325
```
326326

327-
Now it works, because the name `"func"` is function-local. It is not taken from outside (and not visible there). The specification guarantees that it will always reference the current function.
327+
Acum funcționează, deoarece numele `"func"` este local pentru funcții. Nu este preluat din exterior (și nu este vizibil acolo). Specificația garantează că va face întotdeauna referire la funcția curentă.
328328

329-
The outer code still has its variable `sayHi` or `welcome`. And `func` is an "internal function name", the way for the function to can call itself reliably.
329+
Codul exterior are în continuare variabila `sayHi` sau `welcome`. Iar `func` este un "nume de funcție intern", modul în care funcția se poate apela singură în mod fiabil.
330330

331-
```smart header="There's no such thing for Function Declaration"
332-
The "internal name" feature described here is only available for Function Expressions, not for Function Declarations. For Function Declarations, there is no syntax for adding an "internal" name.
331+
```smart header="Nu există așa ceva pentru Function Declaration"
332+
Caracteristica "nume intern" descrisă aici este disponibilă doar pentru Function Expressions, nu și pentru Function Declarations. Pentru Function Declarations, nu există o sintaxă pentru adăugarea unui nume "intern".
333333
334-
Sometimes, when we need a reliable internal name, it's the reason to rewrite a Function Declaration to Named Function Expression form.
334+
Uneori, atunci când avem nevoie de un nume intern fiabil, acesta este motivul pentru a rescrie o Function Declaration sub forma unei Named Function Expression.
335335
```
336336

337337
## Summary

0 commit comments

Comments
 (0)