Skip to content

Commit 82abe8f

Browse files
committed
translated until line 206
1 parent 88edfd9 commit 82abe8f

File tree

1 file changed

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

1 file changed

+32
-32
lines changed

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

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@ alert( arr[0].name ); // <șir gol>
7777

7878
În practică, însă, majoritatea funcțiilor au un nume.
7979

80-
## The "length" property
80+
## Proprietatea "length"
8181

82-
There is another built-in property "length" that returns the number of function parameters, for instance:
82+
Există o altă proprietate încorporată "length" care returnează numărul de parametri ai funcției, de exemplu:
8383

8484
```js run
8585
function f1(a) {}
@@ -91,20 +91,20 @@ alert(f2.length); // 2
9191
alert(many.length); // 2
9292
```
9393

94-
Here we can see that rest parameters are not counted.
94+
Aici putem vedea că parametrii rest nu sunt numărați.
9595

96-
The `length` property is sometimes used for [introspection](https://en.wikipedia.org/wiki/Type_introspection) in functions that operate on other functions.
96+
Proprietatea `length` este uneori utilizată pentru [introspecție](https://en.wikipedia.org/wiki/Type_introspection) în funcțiile care operează pe alte funcții.
9797

98-
For instance, in the code below the `ask` function accepts a `question` to ask and an arbitrary number of `handler` functions to call.
98+
De exemplu, în codul de mai jos funcția `ask` acceptă o `question` pentru a întreba și un număr arbitrar de funcții `handler` pentru a fi apelate.
9999

100-
Once a user provides their answer, the function calls the handlers. We can pass two kinds of handlers:
100+
Odată ce un utilizator le oferă răspunsul, funcția apelează handlerii. Putem trece două tipuri de handlers:
101101

102-
- A zero-argument function, which is only called when the user gives a positive answer.
103-
- A function with arguments, which is called in either case and returns an answer.
102+
- O funcție cu zero argumente, care este apelată doar atunci când utilizatorul dă un răspuns pozitiv.
103+
- O funcție cu argumente, care este apelată în oricare caz și care returnează un răspuns.
104104

105-
To call `handler` the right way, we examine the `handler.length` property.
105+
Pentru a apela `handler` în mod corect, examinăm proprietatea `handler.length`.
106106

107-
The idea is that we have a simple, no-arguments handler syntax for positive cases (most frequent variant), but are able to support universal handlers as well:
107+
Ideea este că avem o sintaxă handler simplă, fără argumente pentru cazurile pozitive (varianta cea mai frecventă), dar suntem capabili să suportăm și handlere universale:
108108

109109
```js run
110110
function ask(question, ...handlers) {
@@ -120,47 +120,47 @@ function ask(question, ...handlers) {
120120

121121
}
122122

123-
// for positive answer, both handlers are called
124-
// for negative answer, only the second one
125-
ask("Question?", () => alert('You said yes'), result => alert(result));
123+
// pentru răspuns pozitiv, ambii gestionari sunt apelați
124+
// pentru răspuns negativ, doar al doilea
125+
ask("Întrebare?", () => alert('Ai spus da'), result => alert(result));
126126
```
127127

128-
This is a particular case of so-called [polymorphism](https://en.wikipedia.org/wiki/Polymorphism_(computer_science)) -- treating arguments differently depending on their type or, in our case depending on the `length`. The idea does have a use in JavaScript libraries.
128+
Acesta este un caz particular al așa-numitului [polimorfism](https://en.wikipedia.org/wiki/Polymorphism_(computer_science)) -- tratarea argumentelor diferit în funcție de tipul lor sau, în cazul nostru în funcție de `length`. Ideea are o utilizare în bibliotecile JavaScript.
129129

130-
## Custom properties
130+
## Proprietăți custom
131131

132-
We can also add properties of our own.
132+
De asemenea putem adăuga proprietăți proprii.
133133

134-
Here we add the `counter` property to track the total calls count:
134+
Aici adăugăm proprietatea `counter` pentru a urmări numărul total de apeluri:
135135

136136
```js run
137137
function sayHi() {
138-
alert("Hi");
138+
alert("Salut");
139139

140140
*!*
141-
// let's count how many times we run
141+
// să numărăm de câte ori se execută
142142
sayHi.counter++;
143143
*/!*
144144
}
145-
sayHi.counter = 0; // initial value
145+
sayHi.counter = 0; // valoare inițială
146146

147-
sayHi(); // Hi
148-
sayHi(); // Hi
147+
sayHi(); // Salut
148+
sayHi(); // Salut
149149

150-
alert( `Called ${sayHi.counter} times` ); // Called 2 times
150+
alert( `Apelat de ${sayHi.counter} ori` ); // Apelat de 2 ori
151151
```
152152

153-
```warn header="A property is not a variable"
154-
A property assigned to a function like `sayHi.counter = 0` does *not* define a local variable `counter` inside it. In other words, a property `counter` and a variable `let counter` are two unrelated things.
153+
```warn header="O proprietate nu este o variabilă"
154+
O proprietate atribuită unei funcții precum `sayHi.counter = 0` *nu* definește o variabilă locală `counter` în interiorul ei. Cu alte cuvinte, o proprietate `counter` și o variabilă `let counter` sunt două lucruri fără legătură.
155155
156-
We can treat a function as an object, store properties in it, but that has no effect on its execution. Variables are not function properties and vice versa. These are just parallel worlds.
156+
Putem trata o funcție ca pe un obiect, putem stoca proprietăți în ea, dar acest lucru nu are niciun efect asupra execuției sale. Variabilele nu sunt proprietăți ale funcțiilor și viceversa. Acestea sunt doar lumi paralele.
157157
```
158158

159-
Function properties can replace closures sometimes. For instance, we can rewrite the counter function example from the chapter <info:closure> to use a function property:
159+
Proprietățile funcțiilor pot înlocui closures uneori. De exemplu, putem rescrie exemplul funcției counter din capitolul <info:closure> pentru a folosi o proprietate de funcție:
160160

161161
```js run
162162
function makeCounter() {
163-
// instead of:
163+
// în loc de:
164164
// let count = 0
165165

166166
function counter() {
@@ -177,11 +177,11 @@ alert( counter() ); // 0
177177
alert( counter() ); // 1
178178
```
179179

180-
The `count` is now stored in the function directly, not in its outer Lexical Environment.
180+
Acum `count` este stocat direct în funcție, nu în mediul său Lexical Environment.
181181

182-
Is it better or worse than using a closure?
182+
Este mai bine sau mai rău decât utilizarea unui closure?
183183

184-
The main difference is that if the value of `count` lives in an outer variable, then external code is unable to access it. Only nested functions may modify it. And if it's bound to a function, then such a thing is possible:
184+
Principala diferență este că dacă valoarea lui `count` trăiește într-o variabilă exterioară, atunci codul extern nu o poate accesa. Doar funcțiile nested o pot modifica. Iar dacă este legată de o funcție, atunci un astfel de lucru este posibil:
185185

186186
```js run
187187
function makeCounter() {
@@ -203,7 +203,7 @@ alert( counter() ); // 10
203203
*/!*
204204
```
205205

206-
So the choice of implementation depends on our aims.
206+
Așadar alegerea implementării depinde de obiectivele noastre.
207207

208208
## Named Function Expression
209209

0 commit comments

Comments
 (0)