Skip to content

Commit 0ed2333

Browse files
authored
Merge pull request #111 from javascript-tutorial/temp
Translation of the article "Arrow functions, the basis"
2 parents 851187f + 9694052 commit 0ed2333

File tree

3 files changed

+44
-44
lines changed

3 files changed

+44
-44
lines changed

1-js/02-first-steps/17-arrow-functions-basics/1-rewrite-arrow/solution.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ function ask(question, yes, no) {
66
}
77

88
ask(
9-
"Do you agree?",
9+
"Ar jus sutinkate?",
1010
*!*
11-
() => alert("You agreed."),
12-
() => alert("You canceled the execution.")
11+
() => alert("Jus sutikote."),
12+
() => alert("Jus atšaukėte vykdymą.")
1313
*/!*
1414
);
1515
```
1616

17-
Looks short and clean, right?
17+
Atrodo trumpai ir švariai, ar ne?
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

2-
# Rewrite with arrow functions
2+
# Perrašykite naudodami rodyklių funkcijas
33

4-
Replace Function Expressions with arrow functions in the code below:
4+
Žemiau pateiktame kode Function Expressions pakeiskite rodyklių funkcijomis:
55

66
```js run
77
function ask(question, yes, no) {
@@ -10,8 +10,8 @@ function ask(question, yes, no) {
1010
}
1111

1212
ask(
13-
"Do you agree?",
14-
function() { alert("You agreed."); },
15-
function() { alert("You canceled the execution."); }
13+
"Ar jus sutinkate?",
14+
function() { alert("Jus sutikote."); },
15+
function() { alert("Jus atšaukėte vykdymą."); }
1616
);
1717
```
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
1-
# Arrow functions, the basics
1+
# Rodyklių funkcijos, pagrindai
22

3-
There's another very simple and concise syntax for creating functions, that's often better than Function Expressions.
3+
Yra dar viena labai paprasta ir glausta funkcijų kūrimo sintaksė, kuri dažnai yra geresnė už Function Expressions.
44

5-
It's called "arrow functions", because it looks like this:
5+
Ji vadinama “rodyklių funkcijomis” (ang. *arrow functions*), nes atrodo taip:
66

77
```js
88
let func = (arg1, arg2, ..., argN) => expression;
99
```
1010

11-
This creates a function `func` that accepts arguments `arg1..argN`, then evaluates the `expression` on the right side with their use and returns its result.
11+
Čia sukuriama funkcija `func`, kuri priima argumentus `arg1..argN`, tada įvertina dešinėje pusėje esantį `expression` su jų panaudojimu ir grąžina rezultatą.
1212

13-
In other words, it's the shorter version of:
13+
Kitaip tariant, tai yra trumpesnė versija:
1414

1515
```js
1616
let func = function(arg1, arg2, ..., argN) {
1717
return expression;
1818
};
1919
```
2020

21-
Let's see a concrete example:
21+
Išnagrinėkime konkretų pavyzdį:
2222

2323
```js run
2424
let sum = (a, b) => a + b;
2525

26-
/* This arrow function is a shorter form of:
26+
/* Ši rodyklės funkcija yra trumpesnė forma:
2727
2828
let sum = function(a, b) {
2929
return a + b;
@@ -33,79 +33,79 @@ let sum = function(a, b) {
3333
alert( sum(1, 2) ); // 3
3434
```
3535

36-
As you can see, `(a, b) => a + b` means a function that accepts two arguments named `a` and `b`. Upon the execution, it evaluates the expression `a + b` and returns the result.
36+
Kaip jūs matote, `(a, b) => a + b` reiškia funkciją, kuri priima du argumentus, pavadintus `a` ir `b`. Vykdymo metu ji įvertina išraišką `a + b` ir grąžina rezultatą.
3737

38-
- If we have only one argument, then parentheses around parameters can be omitted, making that even shorter.
38+
- Jeigu mes turime tik vieną argumentą, skliaustelius aplink parametrus galima praleisti ir taip dar labiau sutrumpinti užrašą
3939

40-
For example:
40+
Pavyzdžiui:
4141

4242
```js run
4343
*!*
4444
let double = n => n * 2;
45-
// roughly the same as: let double = function(n) { return n * 2 }
45+
// maždaug tas pats kaip: let double = function(n) { return n * 2 }
4646
*/!*
4747

4848
alert( double(3) ); // 6
4949
```
5050

51-
- If there are no arguments, parentheses will be empty (but they should be present):
51+
- Jeigu argumentų nėra, skliaustai bus tušti (tačiau jie turėtų būti):
5252

5353
```js run
54-
let sayHi = () => alert("Hello!");
54+
let sayHi = () => alert("Labas!");
5555
5656
sayHi();
5757
```
5858

59-
Arrow functions can be used in the same way as Function Expressions.
59+
Rodyklės funkcijas galima naudoti taip pat, kaip ir Function Expressions.
6060

61-
For instance, to dynamically create a function:
61+
Pavyzdžiui, norėdami dinamiškai sukurti funkciją:
6262

6363
```js run
64-
let age = prompt("What is your age?", 18);
64+
let age = prompt("Koks jūsų amžius?", 18);
6565
6666
let welcome = (age < 18) ?
67-
() => alert('Hello') :
68-
() => alert("Greetings!");
67+
() => alert('Labas!') :
68+
() => alert("Laba diena!");
6969
7070
welcome();
7171
```
7272

73-
Arrow functions may appear unfamiliar and not very readable at first, but that quickly changes as the eyes get used to the structure.
73+
Iš pradžių rodyklių funkcijos gali atrodyti nepažįstamos ir nelabai skaitomos, tačiau tai greitai pasikeičia, kai akys pripranta prie struktūros.
7474

75-
They are very convenient for simple one-line actions, when we're just too lazy to write many words.
75+
Jie labai patogūs atliekant paprastus vienos eilutės veiksmus, kai tiesiog tingime rašyti daug žodžių.
7676

77-
## Multiline arrow functions
77+
## Kelių eilučių rodyklių funkcijos
7878

79-
The examples above took arguments from the left of `=>` and evaluated the right-side expression with them.
79+
Aukščiau pateiktuose pavyzdžiuose buvo paimti argumentai iš `=>` kairės pusės ir su jais įvertinta dešiniosios pusės išraiška.
8080

81-
Sometimes we need something a little bit more complex, like multiple expressions or statements. It is also possible, but we should enclose them in curly braces. Then use a normal `return` within them.
81+
Kartais mums reikia šiek tiek sudėtingesnių dalykų, pavyzdžiui, kelių išraiškų ar teiginių. Tai taip pat įmanoma, tačiau jas turėtume uždaryti figūriniais skliaustais. Tada juose reikia naudoti įprastą `return`.
8282

83-
Like this:
83+
Štai taip:
8484

8585
```js run
86-
let sum = (a, b) => { // the curly brace opens a multiline function
86+
let sum = (a, b) => { // figūrinis skliaustelis atveria kelių eilučių funkciją
8787
let result = a + b;
8888
*!*
89-
return result; // if we use curly braces, then we need an explicit "return"
89+
return result; // jei naudojame figūrinius skliaustus, reikia aiškiai nurodyti "return".
9090
*/!*
9191
};
9292
9393
alert( sum(1, 2) ); // 3
9494
```
9595

96-
```smart header="More to come"
97-
Here we praised arrow functions for brevity. But that's not all!
96+
```smart header="Toliau mes išmoksime daugiau"
97+
Čia mes pateikėme pagrindinę rodyklių funkcijų paskirtį -- trumpumas. Bet tai dar ne viskas!
9898
99-
Arrow functions have other interesting features.
99+
Rodyklių funkcijos turi ir kitų įdomių savybių.
100100
101-
To study them in-depth, we first need to get to know some other aspects of JavaScript, so we'll return to arrow functions later in the chapter <info:arrow-functions>.
101+
Norėdami jas nuodugniai išnagrinėti, pirmiausia turime susipažinti su kitais JavaScript aspektais, todėl prie rodyklių funkcijų grįšime vėliau, skyriuje <info:arrow-functions>.
102102
103-
For now, we can already use arrow functions for one-line actions and callbacks.
103+
O dabar mes jau galime naudoti rodyklių funkcijas vienos eilutės veiksmams ir callback'ams.
104104
```
105105

106-
## Summary
106+
## Santrauka
107107

108-
Arrow functions are handy for one-liners. They come in two flavors:
108+
Rodyklių funkcijos yra patogios, kai reikia parašyti vieną eilutę. Jos būna dviejų rūšių:
109109

110-
1. Without curly braces: `(...args) => expression` -- the right side is an expression: the function evaluates it and returns the result.
111-
2. With curly braces: `(...args) => { body }` -- brackets allow us to write multiple statements inside the function, but we need an explicit `return` to return something.
110+
1. Be figūrinių skliaustų: `(...args) => expression` -- dešinioji išraiškos pusė: funkcija ją apskaičiuoja ir grąžina rezultatą. Skliaustelius galima praleisti, jei yra tik vienas argumentas: `n => n * 2`.
111+
2. Su figūriniais skliaustais: `(...args) => { body }` -- figūriniai skliaustai leidžia įrašyti kelis teiginius funkcijos viduje, tačiau mums reikia aiškaus `return`, kad ką nors grąžintume.

0 commit comments

Comments
 (0)