Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upClass basic syntax #40
Conversation
|
Solved all suggestion /done |
|
|
||
|  | ||
|
|
||
| Here's the code to introspect it: | ||
| Iată codul pentru a-l introspecta: |
|
|
||
| Sometimes people say that `class` is a "syntax sugar" (syntax that is designed to make things easier to read, but doesn't introduce anything new), because we could actually declare the same without `class` keyword at all: | ||
| Câteodată oamenii spun că `class` este sugar syntax (sintaxă proiectată într-o manieră în care este mai ușor de citit, dar care nu introduce nimic nou), pentru că am putea să declarăm o clasă și fără sintaxa implicită, în felul următor: |
lighthousand
Dec 23, 2019
Member
Grammar suggestion : "....sintaxa implicita...." -> "...sintaxa explicita..."
| // 2. Add the method to prototype | ||
| // orice funcție prototip are o proprietate constructor în mode implicit |
lighthousand
Dec 23, 2019
Member
Grammar suggestion : "functie prototip" -> "prototip de functie"
Typo : "mode implicit" -> "mod implicit"
| let user = new User("John"); | ||
| user.sayHi(); | ||
| ``` | ||
| Rezultatul definiției este aproape același. Deci, există întreadevăr motive pentru care `class` poate să fie considerat ca și sugar syntax pentru a definii un constructor împreună cu metodele prototipului. |
|
|
||
| 1. First, a function created by `class` is labelled by a special internal property `[[FunctionKind]]:"classConstructor"`. So it's not entirely the same as creating it manually. | ||
| 1. În primul rând, o funcție creadtă de `class` este marcată de o proprietate internă specială `[[FunctionKind]]:"classConstructor"`. Atlfel, nu este în totalitate același lucru cu crearea manuală a acesteia |
lighthousand
Dec 23, 2019
Member
Grammar suggestion : "cu crearea manuala" -> "ca și crearea manuală"
| ``` | ||
|
|
||
| Also, a string representation of a class constructor in most JavaScript engines starts with the "class..." | ||
| De asemenea, o reprezentare a șirului de caractere a unui constructor de clasă în engine-ul JavaScript începe cu "class..." |
|
|
||
| That's good, because if we `for..in` over an object, we usually don't want its class methods. | ||
| Asta este foarte bine, pentru că daca am folosi `for..in` peste un obiect, nu am vrea toate metodele clasei acestuia. |
| All code inside the class construct is automatically in strict mode. | ||
| 3. Clasele folosesc întotdeauna `use strict`. | ||
| Tot codul din interiorul constructorului clasei este în mod automat in stric mode. | ||
| Tot codul din cadrul constructorului clasei este automatc in strict mode. |
|
|
||
| Besides, `class` syntax brings many other features that we'll explore later. | ||
| În plus, sintaxa `class` aduce mult mai multe caracteristici pe care o să le explorăm în curând. |
|
|
||
| Just like functions, classes can be defined inside another expression, passed around, returned, assigned etc. | ||
| Exact ca și funcțiile, clasele pot să fie definite în interiorul alte expresii, pot să fie trimise dintr-o parte în alta, returnare, alocate etc. |
lighthousand
Dec 23, 2019
Member
Grammar suggestion : "in interiorul alte expresii" -> "in interiorul altor expresii"
lighthousand
Dec 23, 2019
Member
Grammar suggestion : "returnare" -> "returnate"
Grammar suggestion : "alocate" -> "atribuite"
|
|
||
| If a class expression has a name, it's visible inside the class only: | ||
| Daca o expresie a unei clase are un nume, aceasta este vizibil doar în interiorul clasei: |
|
|
||
| If a class expression has a name, it's visible inside the class only: | ||
| Daca o expresie a unei clase are un nume, aceasta este vizibil doar în interiorul clasei: |
|
@Benyaak, you're not a romanian native speaker, am i right ? :) |
| return class { | ||
| sayHi() { | ||
| alert(phrase); | ||
| }; | ||
| }; | ||
| } | ||
| // Create a new class | ||
| let User = makeClass("Hello"); | ||
| // Crează o nouă clasă |
| ``` | ||
|
|
||
|
|
||
| ## Getters/setters, other shorthands | ||
|
|
||
| Just like literal objects, classes may include getters/setters, generators, computed properties etc. | ||
| Exact ca și literal objects, clasele pot include getteri/setter, generatori, proprietăți computed etc. |
| ``` | ||
|
|
||
| The class declaration creates getters and setters in `User.prototype`, like this: | ||
| Declararea clasei crează getteri și setter în `User.prototype`, exact așa: |
| ``` | ||
|
|
||
| The class declaration creates getters and setters in `User.prototype`, like this: | ||
| Declararea clasei crează getteri și setter în `User.prototype`, exact așa: |
| @@ -282,7 +283,7 @@ Object.defineProperties(User.prototype, { | |||
| }); | |||
| ``` | |||
|
|
|||
| Here's an example with a computed property in brackets `[...]`: | |||
| Aici este un exemplu cu o proprietate computed folosită între paranteze `[...]`: | |||
| @@ -298,54 +299,54 @@ class User { | |||
| new User().sayHi(); | |||
| ``` | |||
|
|
|||
| For a generator method, similarly, prepend it with `*`. | |||
| Pentru o metodă generator, similar, o precedăm cu `*`. | |||
| ```warn header="Old browsers may need a polyfill" | ||
| Class-level properties are a recent addition to the language. | ||
| ```warn header="Browserele vechi pot avea nevoie de polyfill" | ||
| Proprietațile la nivel de clasă sunt o adiție recentă. |
| ``` | ||
|
|
||
| In the example above, `User` only had methods. Let's add a property: | ||
| În exemplul de mai sus, `User` avea doar metode. Hai să adăugam o proprietate: |
lighthousand
Dec 23, 2019
Member
Grammar suggestion : "În exemplul de mai sus" -> "Exemplul de mai sus"
| } | ||
| } | ||
| new User().sayHi(); | ||
| ``` | ||
|
|
||
| The property `name` is not placed into `User.prototype`. Instead, it is created by `new` before calling constructor, it's the property of the object itself. | ||
| Proprietatea `name` nu este introdusă în `User.prototype`. În schimb, aceasta este creată de `new` înainte de apelarea constructorului, it's the property of the object itself. |
lighthousand
Dec 23, 2019
Member
There's a part that has not been translated : "it's the property of the object itself."
|
|
||
| ## Summary | ||
| ## Sumar |
|
|
||
| The basic class syntax looks like this: | ||
| Sintaxa de bază a unei clase arată în felul următor: |
|
|
||
| In the next chapters we'll learn more about classes, including inheritance and other features. | ||
| În următoarele capitole o să învățăm mai multe despre clase, printre care o să învătăm despre moșternie și alte caracteristici ale acestora. |
lighthousand
Dec 23, 2019
Member
Grammar suggestion : "alte caracteristici ale acestora" -> "alte caracteristici"
lighthousand
Dec 23, 2019
Member
Grammar suggestion : "printre care o să învătăm despre " -> "printre care moștenire și alte caracteristici"
|
Overall, good job ! |
|
Please make the requested changes. After it, add a comment "/done". |
|
|
Finished the class basic syntax lesson, I hope everything is okay. Waiting for a review/translation suggestions. Thanks a lot.