Skip to content

Commit 83881a1

Browse files
committed
translated until line 58
1 parent da846e9 commit 83881a1

File tree

1 file changed

+21
-21
lines changed
  • 1-js/06-advanced-functions/05-global-object

1 file changed

+21
-21
lines changed

1-js/06-advanced-functions/05-global-object/article.md

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,61 @@
11

2-
# Global object
2+
# Obiect global
33

4-
The global object provides variables and functions that are available anywhere. By default, those that are built into the language or the environment.
4+
Obiectul global oferă variabile și funcții care sunt disponibile oriunde. În mod implicit, cele care sunt încorporate în limbaj sau în mediu.
55

6-
In a browser it is named `window`, for Node.js it is `global`, for other environments it may have another name.
6+
Într-un browser se numește `window`, pentru Node.js este `global`, iar pentru alte medii poate avea un alt nume.
77

8-
Recently, `globalThis` was added to the language, as a standardized name for a global object, that should be supported across all environments. It's supported in all major browsers.
8+
Recent, `globalThis` a fost adăugat în limbaj, ca un nume standardizat pentru un obiect global, care ar trebui să fie acceptat în toate mediile. Este suportat în toate browserele majore.
99

10-
We'll use `window` here, assuming that our environment is a browser. If your script may run in other environments, it's better to use `globalThis` instead.
10+
Vom folosi `window` aici, presupunând că mediul nostru este un browser. Dacă scriptul dvs. ar poate rula în alte medii, este mai bine să folosiți `globalThis` în schimb.
1111

12-
All properties of the global object can be accessed directly:
12+
Toate proprietățile obiectului global pot fi accesate direct:
1313

1414
```js run
15-
alert("Hello");
16-
// is the same as
17-
window.alert("Hello");
15+
alert("Bună ziua");
16+
// este la fel ca
17+
window.alert("Bună ziua");
1818
```
1919

20-
In a browser, global functions and variables declared with `var` (not `let/const`!) become the property of the global object:
20+
Într-un browser, funcțiile și variabilele globale declarate cu `var` (nu cu `let/const`!) devin proprietatea obiectului global:
2121

2222
```js run untrusted refresh
2323
var gVar = 5;
2424

25-
alert(window.gVar); // 5 (became a property of the global object)
25+
alert(window.gVar); // 5 (a devenit o proprietate a obiectului global)
2626
```
2727

28-
Function declarations have the same effect (statements with `function` keyword in the main code flow, not function expressions).
28+
Declarațiile de funcții au același efect (declarații folosind cuvântul cheie `function` în fluxul principal de cod, nu expresii de funcții).
2929

30-
Please don't rely on that! This behavior exists for compatibility reasons. Modern scripts use [JavaScript modules](info:modules) where such a thing doesn't happen.
30+
Vă rugăm să nu vă bazați pe asta! Acest comportament există din motive de compatibilitate. Scripturile moderne folosesc [module JavaScript](info:modules) unde nu se întâmplă așa ceva.
3131

32-
If we used `let` instead, such thing wouldn't happen:
32+
Dacă am folosi în schimb `let`, un astfel de lucru nu s-ar întâmpla:
3333

3434
```js run untrusted refresh
3535
let gLet = 5;
3636

37-
alert(window.gLet); // undefined (doesn't become a property of the global object)
37+
alert(window.gLet); // undefined (nu devine o proprietate a obiectului global)
3838
```
3939

40-
If a value is so important that you'd like to make it available globally, write it directly as a property:
40+
Dacă o valoare este atât de importantă încât doriți să o faceți disponibilă la nivel global, scrieți-o direct ca o proprietate:
4141

4242
```js run
4343
*!*
44-
// make current user information global, to let all scripts access it
44+
// face informațiile despre utilizatorul curent globale, pentru a lăsa toate scripturile să le acceseze
4545
window.currentUser = {
4646
name: "John"
4747
};
4848
*/!*
4949

50-
// somewhere else in code
50+
// în altă parte în cod
5151
alert(currentUser.name); // John
5252

53-
// or, if we have a local variable with the name "currentUser"
54-
// get it from window explicitly (safe!)
53+
// sau, dacă avem o variabilă locală cu numele "currentUser"
54+
// luați-o din window în mod explicit (sigur!)
5555
alert(window.currentUser.name); // John
5656
```
5757

58-
That said, using global variables is generally discouraged. There should be as few global variables as possible. The code design where a function gets "input" variables and produces certain "outcome" is clearer, less prone to errors and easier to test than if it uses outer or global variables.
58+
Acestea fiind spuse, utilizarea variabilelor globale este în general descurajată. Ar trebui să fie cât mai puține variabile globale pe cât posibil. Proiectarea codului în care o funcție primește variabile de "intrare" și produce un anumit "rezultat" este mai clară, mai puțin predispusă la erori și mai ușor de testat decât în cazul în care folosește variabile exterioare sau globale.
5959

6060
## Using for polyfills
6161

0 commit comments

Comments
 (0)