Skip to content

Commit d62c34f

Browse files
committed
almost finished 1.1 subchapter
1 parent d4f050a commit d62c34f

File tree

1 file changed

+44
-47
lines changed

1 file changed

+44
-47
lines changed

1-js/01-getting-started/1-intro/article.md

Lines changed: 44 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,80 @@
1-
# An Introduction to JavaScript
1+
# Įvadas į JavaScript
22

3-
Let's see what's so special about JavaScript, what we can achieve with it, and which other technologies play well with it.
3+
Pažvelkime kuo įpatinga JavaScript kalba, ką mes galime su ja padaryti ir kokios kitos technologijos gali būti naudojamos kartu su ja
44

5-
## What is JavaScript?
5+
## Kas yra JavaScript?
66

7-
*JavaScript* was initially created to *"make web pages alive"*.
7+
Iš pat pradžių *JavaScript* buvo sukurtas tam, kad *"padaryti tinklalapius gyvus"*.
88

9-
The programs in this language are called *scripts*. They can be written right in a web page's HTML and run automatically as the page loads.
9+
Programos, parašytos šia kalba yra vadinamos *skriptais*. Jos gali būti parašytos tinklalapio HTML ir veikti automatiškai, kuomet tinklalapis kraunamas.
1010

11-
Scripts are provided and executed as plain text. They don't need special preparation or compilation to run.
11+
Skriptai yra rašomi ir vykdomi plain tekstu. Jiem nereikia kompiliavimo fazės.
1212

13-
In this aspect, JavaScript is very different from another language called [Java](https://en.wikipedia.org/wiki/Java_(programming_language)).
13+
Šiuo aspektu JavaScript labai skiriasi nuo [Java](https://en.wikipedia.org/wiki/Java_(programming_language)).
1414

15-
```smart header="Why is it called <u>Java</u>Script?"
16-
When JavaScript was created, it initially had another name: "LiveScript". But Java was very popular at that time, so it was decided that positioning a new language as a "younger brother" of Java would help.
15+
```smart header="Iš kur kilo pavadinimas JavaScript?"
16+
Iš pat pradžių JavaScript turėjo kitą pavadinimą: "LiveScript". Tačiau Java buvo itin populiari, todėl buvo nuspręsta pateikti naują kalbą kaip Java "jaunesnį brolį".
1717
18-
But as it evolved, JavaScript became a fully independent language with its own specification called [ECMAScript](http://en.wikipedia.org/wiki/ECMAScript), and now it has no relation to Java at all.
18+
Tačiau ilgainiui JavaScript tapo nepriklausoma kalba, turinti atskirą specifikaciją, kuri vadinama [ECMAScript](http://en.wikipedia.org/wiki/ECMAScript). Šiuo metu JavaScript ir Java neturi nieko bendro.
1919
```
2020

21-
Today, JavaScript can execute not only in the browser, but also on the server, or actually on any device that has a special program called [the JavaScript engine](https://en.wikipedia.org/wiki/JavaScript_engine).
21+
Dabar JavaScript gali būti vykdomas ne tik naršyklėje, bet taip pat ir serveryje arba praktiškai bet kokiame įrenginyje, kuris turi specialią programą, vadinama JavaScript varikliu [(JavaScript engine)](https://en.wikipedia.org/wiki/JavaScript_engine).
2222

23-
The browser has an embedded engine sometimes called a "JavaScript virtual machine".
23+
Naršyklės turi savo vidinį variklį, kuris kartais vadinamas "JavaScript virtuali mašiną"
2424

25-
Different engines have different "codenames". For example:
25+
Skirtingi varikliai turi skirtingus "nickus". Pavyzdžiui:
2626

27-
- [V8](https://en.wikipedia.org/wiki/V8_(JavaScript_engine)) -- in Chrome and Opera.
28-
- [SpiderMonkey](https://en.wikipedia.org/wiki/SpiderMonkey) -- in Firefox.
29-
- ...There are other codenames like "Trident" and "Chakra" for different versions of IE, "ChakraCore" for Microsoft Edge, "Nitro" and "SquirrelFish" for Safari, etc.
27+
- [V8](https://en.wikipedia.org/wiki/V8_(JavaScript_engine)) -- Chrome ir Opera.
28+
- [SpiderMonkey](https://en.wikipedia.org/wiki/SpiderMonkey) -- Firefox.
29+
- Egzistuoja kitų nickų, tokių kaip "Trident", "Chakra" skirtingom IE versijom, "ChakraCore" Microsoft Edge naršklėje, "Nitro" ir "SquirellFish" Safari ir t.t.
3030

31-
The terms above are good to remember because they are used in developer articles on the internet. We'll use them too. For instance, if "a feature X is supported by V8", then it probably works in Chrome and Opera.
31+
Šias sąvokas verta atsiminti, nes jos naudojamos straipsniuose, skirtuose programuotojams. Mes taip pat jas naudosime. Pavyzdžiui, jeigu "feature X yra palaikoma V8", reiškias jinai ko gero veikia Chrome ir Opera naršklėse.
3232

33-
```smart header="How do engines work?"
33+
```smart header="Kaip veikia varikliai?"
3434
35-
Engines are complicated. But the basics are easy.
35+
Varikliai yra sudėtingi daiktai, bet basic'ai yra paprasti.
3636
37-
1. The engine (embedded if it's a browser) reads ("parses") the script.
38-
2. Then it converts ("compiles") the script to the machine language.
39-
3. And then the machine code runs, pretty fast.
37+
1. Variklis (vidinis, jei jis yra naršyklėje) skaito ("parsina") skriptą.
38+
2. Konvertuoja ("kompiliuoja") skriptą į mašininį kodą.
39+
3. Vykdomas mašininis kodas.
4040
41-
The engine applies optimizations at each step of the process. It even watches the compiled script as it runs, analyzes the data that flows through it, and applies optimizations to the machine code based on that knowledge. When it's done, scripts run quite fast.
41+
Varikliai optimizuoja kodą kiekviename žingsnyje. Jie netgi stebi sukompiliuotą skriptą, kuomet jis vykdomas, bei analizuoja duomenis, kurie jame naudojami, ir pagal tai taiko papildomas optimizacijas. Po viso šio procesio, skriptai yra vykdomi gan greitai.
4242
```
4343

44-
## What can in-browser JavaScript do?
44+
## Ką gali JavaScript'as padaryti naršyklėje?
4545

46-
Modern JavaScript is a "safe" programming language. It does not provide low-level access to memory or CPU, because it was initially created for browsers which do not require it.
46+
Modernus JavaScript'as yra "saugi" programavimo kalba. Ji neleidžia programuotojui pasiekti atminties arba CPU, nes iš pat pradžių ji buvo sukurta naršklėm, kuriom to nereikia.
4747

48-
JavaScript's capabilities greatly depend on the environment it's running in. For instance, [Node.js](https://wikipedia.org/wiki/Node.js) supports functions that allow JavaScript to read/write arbitrary files, perform network requests, etc.
48+
JavaScript'o galimybės stipriai priklauso nuo aplinkos, kurioje jis vykdomas. Pavyzdžiui, [Node.js](https://wikipedia.org/wiki/Node.js) palaiko funkcijas, kurios leidžia Javascript'ui skaityti/rašyti failus, vykdyti kompiuterių tinklų užklausas ir pan.
4949

50-
In-browser JavaScript can do everything related to webpage manipulation, interaction with the user, and the webserver.
50+
Naršyklėje JavaScript'as gali daryti bet ką, kas liečia tinklalapio manipuliacijas, interakcijas su vartotojais ir web serveriu.
5151

52-
For instance, in-browser JavaScript is able to:
52+
Pavyzdžiui, JavaScript'as naršyklėje gali:
5353

54-
- Add new HTML to the page, change the existing content, modify styles.
55-
- React to user actions, run on mouse clicks, pointer movements, key presses.
56-
- Send requests over the network to remote servers, download and upload files (so-called [AJAX](https://en.wikipedia.org/wiki/Ajax_(programming)) and [COMET](https://en.wikipedia.org/wiki/Comet_(programming)) technologies).
57-
- Get and set cookies, ask questions to the visitor, show messages.
58-
- Remember the data on the client-side ("local storage").
54+
- Pridėti naują HTML į tinklalapį, pakeisti jau esamą turinį, pakeisti stilius.
55+
- Reaguoti į vartotojo veiksmus, pelės, klaviatūros paspaudimus.
56+
- Siųsti užklausas į remote serverius, atsisiųsti ir upload'inti failus ([AJAX](https://en.wikipedia.org/wiki/Ajax_(programming)) ir [COMET](https://en.wikipedia.org/wiki/Comet_(programming)) technologijos).
57+
- Gauti ir nustatyti cookies, klausti vartotojo, parodyti žinutes.
58+
- Išsaugoti duomenis kliento pusėje ("local storage").
5959

60-
## What CAN'T in-browser JavaScript do?
60+
## Ko NEGALI JavaScript'as naršyklėje?
6161

62-
JavaScript's abilities in the browser are limited for the sake of the user's safety. The aim is to prevent an evil webpage from accessing private information or harming the user's data.
62+
JavaScript'o galimybės naryklėje yra ribojamos dėl vartotojų saugumo. Tikslas - neleisti tinklalapiam pasiekti privačius duomenis arba žaloti vartotojo duomenis.
6363

64-
Examples of such restrictions include:
64+
Ribojimų pavyzdžiai:
65+
- JavaScript'as tinklalapyje negali skaityti/rašyti failus kietajame diske, juos kopijuoti arba vykdyti programas. JavaScript'as neturi tiesioginios prieigos prie operacinės sistemos funkcijų.
6566

66-
- JavaScript on a webpage may not read/write arbitrary files on the hard disk, copy them or execute programs. It has no direct access to OS system functions.
67+
Modernios naršklės leidžia dirbti su failais, bet prieiga ribojama ir tai leidžiama tik jeigu vartotojas įvykdo kažką konkretaus. Pavyzdžiui, dragg'ina failą į naršklę arba pažymi failą per `<input>` tagą.
6768

68-
Modern browsers allow it to work with files, but the access is limited and only provided if the user does certain actions, like "dropping" a file into a browser window or selecting it via an `<input>` tag.
69-
70-
There are ways to interact with camera/microphone and other devices, but they require a user's explicit permission. So a JavaScript-enabled page may not sneakily enable a web-camera, observe the surroundings and send the information to the [NSA](https://en.wikipedia.org/wiki/National_Security_Agency).
71-
- Different tabs/windows generally do not know about each other. Sometimes they do, for example when one window uses JavaScript to open the other one. But even in this case, JavaScript from one page may not access the other if they come from different sites (from a different domain, protocol or port).
72-
73-
This is called the "Same Origin Policy". To work around that, *both pages* must agree for data exchange and contain a special JavaScript code that handles it. We'll cover that in the tutorial.
74-
75-
This limitation is, again, for the user's safety. A page from `http://anysite.com` which a user has opened must not be able to access another browser tab with the URL `http://gmail.com` and steal information from there.
76-
- JavaScript can easily communicate over the net to the server where the current page came from. But its ability to receive data from other sites/domains is crippled. Though possible, it requires explicit agreement (expressed in HTTP headers) from the remote side. Once again, that's a safety limitation.
69+
Yra būdų komunikuoti su kamera/mikrofonu ir kitais įrenginiais, bet tai reikalauja išreikštinio vartotojo leidimo. Taigi, JavaScript'inis tinklalapis negali suktai įjungti web kamerą, stebėti aplinką ir siųsti informaciją į [NSA](https://en.wikipedia.org/wiki/National_Security_Agency).
70+
- Skirtingi tabai dažniausiai nežino vienas apie kitą. Tačiau kartais vienas tab'as naudoja JavaScript'ą tam, kad atidarytų kitą tab'ą, bet netgi tokiu atveju, JavaScript'as viename tab'e negali pasiekti kito tab'o, jeigu jie ateina iš skirtingų tinklalapių (skirtingas domenas, protokolas arba portas).
71+
Tai vadinama "Same Origin Policy". Tam, kad tai apeiti, *abudu tinklalapiai* turi sutikti apsikeisti duomenimis ir turėti specialų JavaScript kodą, kuris tai handlintų. Mes apie tai kalbėsime viename iš tutorialų.
72+
Šis ribojimas yra, vėlgi, dėl vartotojų saugmo. Tinklapis `http://anysite.com`, kurį vartotojas atidarė, neturėtų pasiekti kito naršklės tabo su URL `http://gmail.com` ir vogti informaciją.
73+
- JavaScript'as gali lengvai komunikuoti internetu su serveriu, iš kurio atėjo tinklalapis. Bet tinklalapio galimybės gauti duomenis iš kitų tinklapių/duomenų yra kiek sudėtingesnės. Nors ir įmanoma, tai reikalauja išreikštinio susitarimo (per HTTP header'ius) iš remote serverio pusės. Vėlgi, dėl saugumo priežasčių.
7774

7875
![](limitations.svg)
7976

80-
Such limits do not exist if JavaScript is used outside of the browser, for example on a server. Modern browsers also allow plugin/extensions which may ask for extended permissions.
77+
Šių ribojimų nėra, jeigu JavaScript'as vykdomas ne naršyklėje, bet, pavyzdžiui, serveryje. Šiuolaikinės naršyklės taip pat turi plugin'us/extension'us, kurie gali prašyti vartotojų leidimo.
8178

8279
## What makes JavaScript unique?
8380

0 commit comments

Comments
 (0)