Skip to content

Commit 8ab4ab8

Browse files
committed
Partial translation of article.md
1 parent e28189e commit 8ab4ab8

File tree

1 file changed

+80
-80
lines changed

1 file changed

+80
-80
lines changed

1-js/04-object-basics/01-object/article.md

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

2-
# Objects
2+
# Obiecte
33

4-
As we know from the chapter <info:types>, there are seven data types in JavaScript. Six of them are called "primitive", because their values contain only a single thing (be it a string or a number or whatever).
4+
Așa cum știm din capitolul <info:types>, în JavaScript există șapte tipuri de date. Șase dintre ele sunt denumite "primitive", pentru că ele conțin numai un singur lucru (fie un string, un număr sau altceva).
55

6-
In contrast, objects are used to store keyed collections of various data and more complex entities. In JavaScript, objects penetrate almost every aspect of the language. So we must understand them first before going in-depth anywhere else.
6+
În contrast, obiectele sunt folosite pentru a stoca colecții indexate de date diferite si alte entități complexe. În JavaScript, obiectele pătrund în aproape toate aspectele limbajului. De aceea trebuie să ințelegem obiectele înainte de a intra mai adânc în altă parte.
77

8-
An object can be created with figure brackets `{…}` with an optional list of *properties*. A property is a "key: value" pair, where `key` is a string (also called a "property name"), and `value` can be anything.
8+
Un obiect poate fi creat folosind acoladele `{…}` cu o listă opțională de *proprietăți*. O proprietate este o pereche "cheie: valoare", unde `cheie` este un string (denumit si "numele proprietății"), iar `valoare` poate fi orice.
99

10-
We can imagine an object as a cabinet with signed files. Every piece of data is stored in its file by the key. It's easy to find a file by its name or add/remove a file.
10+
Ne putem imagina un obiect ca fiind un dosar ce conține documente semnate. Fiecare bucățică de informație este stocată în dosarul ei după `cheie`. Este ușor să găsești un document după nume sau să adaugi/îndepărtezi un document.
1111

1212
![](object.svg)
1313

14-
An empty object ("empty cabinet") can be created using one of two syntaxes:
14+
Un obiect gol ("dosar gol") poate fi creat folosind una dintre următoarele sintaxe:
1515

1616
```js
17-
let user = new Object(); // "object constructor" syntax
18-
let user = {}; // "object literal" syntax
17+
let user = new Object(); // sintaxa "constructor obiect"
18+
let user = {}; // sintaxa "obiect literal"
1919
```
2020

2121
![](object-user-empty.svg)
2222

23-
Usually, the figure brackets `{...}` are used. That declaration is called an *object literal*.
23+
Uzual se folosesc acoladele `{...}`. Această declarație este denumită *obiect literal*.
2424

25-
## Literals and properties
25+
## Literalele și proprietățile
2626

27-
We can immediately put some properties into `{...}` as "key: value" pairs:
27+
Putem pune imediat câteva proprietăți în `{...}` ca și perechi "cheie: valoare":
2828

2929
```js
30-
let user = { // an object
31-
name: "John", // by key "name" store value "John"
32-
age: 30 // by key "age" store value 30
30+
let user = { // un obiect
31+
name: "John", // după cheia "name" stocăm valoarea "John"
32+
age: 30 // dupa cheia "age" stocăm valoarea 30
3333
};
3434
```
3535

36-
A property has a key (also known as "name" or "identifier") before the colon `":"` and a value to the right of it.
36+
O proprietate are o cheie (denumită și "nume" sau "identificator") înainte de semnul două puncte `":"` și o valoare la dreapta semnului.
3737

38-
In the `user` object, there are two properties:
38+
În obiectul `user`, există două proprietăți:
3939

40-
1. The first property has the name `"name"` and the value `"John"`.
41-
2. The second one has the name `"age"` and the value `30`.
40+
1. Prima proprietate are numele `"name"` și valoarea `"John"`.
41+
2. A doua are numele `"age"` și valoarea `30`.
4242

43-
The resulting `user` object can be imagined as a cabinet with two signed files labeled "name" and "age".
43+
Obiectul rezultat `user` poate fi imaginat ca un dosar cu două documente marcate cu "name" respectiv "age".
4444

4545
![user object](object-user.svg)
4646

47-
We can add, remove and read files from it any time.
47+
Putem adăuga, șterge sau citi documente din dosar la orice moment.
4848

49-
Property values are accessible using the dot notation:
49+
Valorile proprietăților sunt accesibile folosind notația cu punct.
5050

5151
```js
52-
// get property values of the object:
52+
// citește valorile proprietăților obiectului:
5353
alert( user.name ); // John
5454
alert( user.age ); // 30
5555
```
5656

57-
The value can be of any type. Let's add a boolean one:
57+
Valoarea poate avea orice tip. Să adăugăm una de tip `boolean`:
5858

5959
```js
6060
user.isAdmin = true;
6161
```
6262

6363
![user object 2](object-user-isadmin.svg)
6464

65-
To remove a property, we can use `delete` operator:
65+
Pentru a șterge o proprietate, putem folosi operatorul `delete`:
6666

6767
```js
6868
delete user.age;
6969
```
7070

7171
![user object 3](object-user-delete.svg)
7272

73-
We can also use multiword property names, but then they must be quoted:
73+
Putem folosi de asemenea mai multe cuvinte ca și nume ale proprietăților, dar acestea trebuie sa fie între ghilimele:
7474

7575
```js
7676
let user = {
7777
name: "John",
7878
age: 30,
79-
"likes birds": true // multiword property name must be quoted
79+
"likes birds": true // numele proprietăților formate din mai multe cuvinte trebuie să fie între ghilimele
8080
};
8181
```
8282

8383
![](object-user-props.svg)
8484

8585

86-
The last property in the list may end with a comma:
86+
Ultima proprietate din listă se poate termina cu virgulă:
8787
```js
8888
let user = {
8989
name: "John",
9090
age: 30*!*,*/!*
9191
}
9292
```
93-
That is called a "trailing" or "hanging" comma. Makes it easier to add/remove/move around properties, because all lines become alike.
93+
Aceasta se numește virgulă "de sfârșit" sau "agățatoare". In felul acesta este mai ușor de adăugat/șters/mutat în jurul proprietăților, deoarece toate liniile vor fi asemănătoare.
9494

95-
## Square brackets
95+
## Paranteze pătrate
9696

97-
For multiword properties, the dot access doesn't work:
97+
Accesul la proprietățile formate din mai multe cuvinte nu se poate face cu punct:
9898

9999
```js run
100-
// this would give a syntax error
100+
// aceasta va genera o erroare de sintaxă
101101
user.likes birds = true
102102
```
103103

104-
That's because the dot requires the key to be a valid variable identifier. That is: no spaces and other limitations.
104+
Asta deorece cheia trebuie să fie un identificator valid pentru o variabilă, adică: fără spații și alte limitări.
105105

106-
There's an alternative "square bracket notation" that works with any string:
106+
Există ca alternativă "notația parantezelor pătrate" care funcționează cu orice fel de șir de caractere:
107107

108108
```js run
109109
let user = {};
@@ -118,20 +118,20 @@ alert(user["likes birds"]); // true
118118
delete user["likes birds"];
119119
```
120120

121-
Now everything is fine. Please note that the string inside the brackets is properly quoted (any type of quotes will do).
121+
Acum totul este în regulă. De remarcat că șirul de caractere este citat corespunzător (oricare dintre semnele pentru ghilimele se accepta).
122122

123-
Square brackets also provide a way to obtain the property name as the result of any expression -- as opposed to a literal string -- like from a variable as follows:
123+
Cu parantezele pătrate se poate obține numele proprietății ca rezultat al unei expresii -- as opposed to a literal string -- dintr-o variabilă:
124124

125125
```js
126126
let key = "likes birds";
127127

128-
// same as user["likes birds"] = true;
128+
// la fel ca user["likes birds"] = true;
129129
user[key] = true;
130130
```
131131

132-
Here, the variable `key` may be calculated at run-time or depend on the user input. And then we use it to access the property. That gives us a great deal of flexibility.
132+
Aici, variabila `key` poate fi calculată la timpul rulării sau poate depinde de datele introduse de utilizatori. Dupa aceea o putem folosi pentru a accesa proprietatea. Acest lucru ne oferă o flexibilitate mărită.
133133

134-
For instance:
134+
De exemplu:
135135

136136
```js run
137137
let user = {
@@ -145,7 +145,7 @@ let key = prompt("What do you want to know about the user?", "name");
145145
alert( user[key] ); // John (if enter "name")
146146
```
147147

148-
The dot notation cannot be used in a similar way:
148+
Notația cu punct nu poate fi folosită în același mod:
149149

150150
```js run
151151
let user = {
@@ -157,40 +157,40 @@ let key = "name";
157157
alert( user.key ) // undefined
158158
```
159159

160-
### Computed properties
160+
### Proprietăți calculate
161161

162-
We can use square brackets in an object literal. That's called *computed properties*.
162+
Putem folosi parantezele pătrate intr-un obiect literal. Asta se numește *proprietate calculată*.
163163

164-
For instance:
164+
De exemplu:
165165

166166
```js run
167167
let fruit = prompt("Which fruit to buy?", "apple");
168168

169169
let bag = {
170170
*!*
171-
[fruit]: 5, // the name of the property is taken from the variable fruit
171+
[fruit]: 5, // numele proprietații este luat din variabila fruit
172172
*/!*
173173
};
174174

175175
alert( bag.apple ); // 5 if fruit="apple"
176176
```
177177

178-
The meaning of a computed property is simple: `[fruit]` means that the property name should be taken from `fruit`.
178+
Semnificația unei proprietăți calculate este simplă: `[fruit]` inseamnă că numele proprietății trebuie obținut din `fruit`.
179179

180-
So, if a visitor enters `"apple"`, `bag` will become `{apple: 5}`.
180+
Deci, daca un vizitator introduce `"apple"`, `bag` va deveni `{apple: 5}`.
181181

182-
Essentially, that works the same as:
182+
În principiu, are aceeași funcționalitate ca și:
183183
```js run
184184
let fruit = prompt("Which fruit to buy?", "apple");
185185
let bag = {};
186186

187-
// take property name from the fruit variable
187+
// obține numele proprietății din variabila fruit
188188
bag[fruit] = 5;
189189
```
190190

191-
...But looks nicer.
191+
...Dar arată mai bine.
192192

193-
We can use more complex expressions inside square brackets:
193+
Putem folosi expresii mai complexe între parantezele pătrate:
194194

195195
```js
196196
let fruit = 'apple';
@@ -199,16 +199,16 @@ let bag = {
199199
};
200200
```
201201

202-
Square brackets are much more powerful than the dot notation. They allow any property names and variables. But they are also more cumbersome to write.
202+
Parantezele pătrate sunt mult mai puternice decât notația cu punct. Ele permit orice fel de nume și de variabile pentru proprietăți, dar sunt mai dificil de scris.
203203

204-
So most of the time, when property names are known and simple, the dot is used. And if we need something more complex, then we switch to square brackets.
204+
Deci, de cele mai multe ori, când numele proprietăților sunt cunoscute și simple se folosește punctul, iar daca avem nevoie de ceva mai complex, trecem la parantezele pătrate.
205205

206206

207207

208-
````smart header="Reserved words are allowed as property names"
209-
A variable cannot have a name equal to one of language-reserved words like "for", "let", "return" etc.
208+
````smart header="Cuvintele rezervate sunt permise ca nume de proprietăți"
209+
O variabilă nu poate avea un nume identic cu unul dintre cuvintele rezervate limbajului precum "for", "let", "return" etc.
210210
211-
But for an object property, there's no such restriction. Any name is fine:
211+
În schimb, pentru o proprietate a unui obiect nu există o astfel de restricție. Orice nume este bun:
212212
213213
```js run
214214
let obj = {
@@ -220,31 +220,31 @@ let obj = {
220220
alert( obj.for + obj.let + obj.return ); // 6
221221
```
222222
223-
Basically, any name is allowed, but there's a special one: `"__proto__"` that gets special treatment for historical reasons. For instance, we can't set it to a non-object value:
223+
Practic, orice nume este permis, însă există unul special: `"__proto__"` care primește un tratament preferențial din motive istorice. De exemplu, nu îl putem seta la o valoare non-obiect:
224224
225225
```js run
226226
let obj = {};
227227
obj.__proto__ = 5;
228-
alert(obj.__proto__); // [object Object], didn't work as intended
228+
alert(obj.__proto__); // [object Object], nu a funcționat cum ne-am așteptat
229229
```
230230
231-
As we see from the code, the assignment to a primitive `5` is ignored.
231+
După cum vedem din cod, atribuirea către o primitivă `5` este ignorată.
232232
233-
That can become a source of bugs and even vulnerabilities if we intend to store arbitrary key-value pairs in an object, and allow a visitor to specify the keys.
233+
Acest lucru poate deveni o sursă de bug-uri și chiar vulnerabilități dacă intenționăm să stocăm perechi cheie-valoare arbitrare într-un obiect și să permitem unui vizitator să specifice cheile.
234234
235-
In that case the visitor may choose `__proto__` as the key, and the assignment logic will be ruined (as shown above).
235+
În acest caz vizitatorul poate alege `__proto__` ca și cheie, iar logica de atribuire va fi stricată (după cum se arată mai sus).
236236
237-
There is a way to make objects treat `__proto__` as a regular property, which we'll cover later, but first we need to know more about objects.
237+
Există o modalitate, pe care o vom acoperi mai târziu, de a face obiectele să trateze `__proto__` ca pe o proprietate obișnuită, dar mai întâi trebuie să știm mai multe despre obiecte.
238238
239-
There's also another data structure [Map](info:map-set), that we'll learn in the chapter <info:map-set>, which supports arbitrary keys.
239+
Există, de asemenea, o altă structură de date [Map](info:map-set), pe care o vom învăța în capitolul <info:map-set>, care acceptă chei arbitrare.
240240
````
241241

242242

243-
## Property value shorthand
243+
## Prescurtare (shorthand) pentru valoarea proprietății
244244

245-
In real code we often use existing variables as values for property names.
245+
În cod real folosim des variabile existente ca valori pentru numele proprietăților.
246246

247-
For instance:
247+
De exemplu:
248248

249249
```js run
250250
function makeUser(name, age) {
@@ -259,60 +259,60 @@ let user = makeUser("John", 30);
259259
alert(user.name); // John
260260
```
261261

262-
In the example above, properties have the same names as variables. The use-case of making a property from a variable is so common, that there's a special *property value shorthand* to make it shorter.
262+
În exemplul de mai sus, proprietățile au aceleași nume ca variabilele. Cazul de utilizare al creării unei proprietăți dintr-o variabilă este atât de comun, încât există un *shorthand al valorii proprietății* pentru a o face mai scurtă.
263263

264-
Instead of `name:name` we can just write `name`, like this:
264+
In loc de `name:name` putem scrie doar `name`, după cum urmeză:
265265

266266
```js
267267
function makeUser(name, age) {
268268
*!*
269269
return {
270-
name, // same as name: name
271-
age // same as age: age
270+
name, // la fel ca name: name
271+
age // la fel ca age: age
272272
// ...
273273
};
274274
*/!*
275275
}
276276
```
277277

278-
We can use both normal properties and shorthands in the same object:
278+
Putem folosi atât proprietăți normale, cât și shorthand-uri în același obiect:
279279

280280
```js
281281
let user = {
282-
name, // same as name:name
282+
name, // la fel ca name:name
283283
age: 30
284284
};
285285
```
286286

287-
## Existence check
287+
## Verificarea existenței
288288

289-
A notable objects feature is that it's possible to access any property. There will be no error if the property doesn't exist! Accessing a non-existing property just returns `undefined`. It provides a very common way to test whether the property exists -- to get it and compare vs undefined:
289+
O caracteristică notabilă a obiectelor este posibilitatea accesării oricărei proprietăți. Nu va fi nicio eroare dacă proprietatea nu există! Accesarea unei proprietăți inexistente doar returnează `undefined`. Oferă un mod foarte comun de a testa dacă proprietatea există -- de a o obține și a o compara cu undefined:
290290

291291
```js run
292292
let user = {};
293293

294-
alert( user.noSuchProperty === undefined ); // true means "no such property"
294+
alert( user.noSuchProperty === undefined ); // true înseamna "nu există proprietatea"
295295
```
296296

297-
There also exists a special operator `"in"` to check for the existence of a property.
297+
Există, de asemenea, un operator special `"in"` pentru a verifica existența unei proprietăți.
298298

299-
The syntax is:
299+
Sintaxa este:
300300
```js
301301
"key" in object
302302
```
303303

304-
For instance:
304+
De exemplu:
305305

306306
```js run
307307
let user = { name: "John", age: 30 };
308308

309-
alert( "age" in user ); // true, user.age exists
310-
alert( "blabla" in user ); // false, user.blabla doesn't exist
309+
alert( "age" in user ); // true, user.age există
310+
alert( "blabla" in user ); // false, user.blabla nu există
311311
```
312312

313-
Please note that on the left side of `in` there must be a *property name*. That's usually a quoted string.
313+
Luați aminte că, la stânga operatorului `in` trebuie sa fie un *nume de proprietate*. Usual este un sir caractere între ghilimele.
314314

315-
If we omit quotes, that would mean a variable containing the actual name will be tested. For instance:
315+
Daca omitem ghilimelele, asta ar însemna că o variabilă care conține de fapt numele va fi testată. De exemplu:
316316

317317
```js run
318318
let user = { age: 30 };

0 commit comments

Comments
 (0)