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
+14-14Lines changed: 14 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -365,24 +365,24 @@ let g = f(); // cât timp există funcția g, valoarea rămâne în memorie
365
365
g =null; // ...și acum memoria este curățată
366
366
```
367
367
368
-
### Real-life optimizations
368
+
### Optimizări în viața reală
369
369
370
-
As we've seen, in theory while a function is alive, all outer variables are also retained.
370
+
După cum am văzut, în teorie cât timp o funcție este activă, toate variabilele exterioare sunt de asemenea păstrate.
371
371
372
-
But in practice, JavaScript engines try to optimize that. They analyze variable usage and if it's obvious from the code that an outer variable is not used -- it is removed.
372
+
Dar în practică, motoarele JavaScript încearcă să optimizeze acest lucru. Ele analizează utilizarea variabilelor și dacă este evident din cod că o variabilă exterioară nu este utilizată -- aceasta este eliminată.
373
373
374
-
**An important side effect in V8 (Chrome, Edge, Opera) is that such variable will become unavailable in debugging.**
374
+
**Un efect secundar important în V8 (Chrome, Edge, Opera) este că o astfel de variabilă va deveni indisponibilă în depanare.**
375
375
376
-
Try running the example below in Chrome with the Developer Tools open.
376
+
Încercați să rulați exemplul de mai jos în Chrome cu Instrumente de dezvoltare deschise.
377
377
378
-
When it pauses, in the console type`alert(value)`.
378
+
Când se întrerupe, în consolă tastați`alert(value)`.
379
379
380
380
```js run
381
381
functionf() {
382
382
let value =Math.random();
383
383
384
384
functiong() {
385
-
debugger; //in console: type alert(value); No such variable!
385
+
debugger; //în consolă: tastați alert(value); Nu există o astfel de variabilă!
386
386
}
387
387
388
388
return g;
@@ -392,18 +392,18 @@ let g = f();
392
392
g();
393
393
```
394
394
395
-
As you could see -- there is no such variable! In theory, it should be accessible, but the engine optimized it out.
395
+
După cum ați putut vedea -- nu există o astfel de variabilă! În teorie, ar trebui să fie accesibilă, dar motorul a optimizat-o.
396
396
397
-
That may lead to funny (if not such time-consuming) debugging issues. One of them -- we can see a same-named outer variable instead of the expected one:
397
+
Acest lucru poate duce la probleme de depanare amuzante (dacă nu ar fi atât de consumatoare de timp). Una dintre ele -- putem vedea o variabilă exterioară cu același nume în locul celei așteptate:
398
398
399
399
```js run global
400
-
let value ="Surprise!";
400
+
let value ="Surpriză!";
401
401
402
402
functionf() {
403
-
let value ="the closest value";
403
+
let value ="cea mai apropiată valoare";
404
404
405
405
functiong() {
406
-
debugger; //in console: type alert(value); Surprise!
This feature of V8 is good to know. If you are debugging with Chrome/Edge/Opera, sooner or later you will meet it.
416
+
Această caracteristică a V8 este bine de știut. Dacă faceți depanare cu Chrome/Edge/Opera, mai devreme sau mai târziu o veți întâlni.
417
417
418
-
That is not a bug in the debugger, but rather a special feature of V8. Perhaps it will be changed sometime. You can always check for it by running the examples on this page.
418
+
Nu este o eroare a depanatorului, ci mai degrabă o caracteristică specială a V8. Poate că va fi schimbată cândva. Puteți oricând să o verificați rulând exemplele de pe această pagină.
0 commit comments