You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 1-js/1-getting-started/1-intro/article.md
+50-55Lines changed: 50 additions & 55 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,97 +4,93 @@ Let's see what's so special about JavaScript, what we can achieve with it and wh
4
4
5
5
## What is JavaScript?
6
6
7
-
*JavaScript* was initially created to *make webpages live".
7
+
*JavaScript* was initially created to *"make webpages alive"*.
8
8
9
9
The programs in this language are called *scripts*. They are put directly into HTML and execute automatically as it loads.
10
10
11
-
**Scripts are provided and executed a plain text.**.
12
-
13
-
They don't need a special preparation or compilation to run.
11
+
Scripts are provided and executed a plain text. They don't need a special preparation or compilation to run.
14
12
15
13
In this aspect, JavaScript is very different from another language called [Java](http://en.wikipedia.org/wiki/Java).
16
14
17
15
[smart header="Why <u>Java</u>Script?"]
18
-
When JavaScript was created, it initially had another name: "LiveScript". But Java language was very popular at that time and it was decided that positioning a new language as a "younger brother" to Java would help.
16
+
When JavaScript was created, it initially had another name: "LiveScript". But Java language was very popular at that time, so it was decided that positioning a new language as a "younger brother" of Java would help.
19
17
20
-
But as it evolved, JavaScript became a fully independent language, with its specification called [ECMAScript](http://en.wikipedia.org/wiki/ECMAScript), and has no relation to Java altogether.
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 altogether.
21
19
22
-
It has quite a few special features that make mastering it a bit hard at first, but we'll deal with them as the tutorial goes on.
20
+
It has quite a few special features that make mastering a bit hard at first, but we'll nicely deal with them later.
23
21
[/smart]
24
22
25
23
JavaScript can execute not only in the browser, but anywhere, with the help of a special program called [an interpreter]("http://en.wikipedia.org/wiki/Interpreter_(computing)"). The execution process is called "an interpretation".
26
24
27
-
[smart header="Compilation and interpretation, for programmers"]
28
-
There are in fact two main means to execute programs: "compilers" and "interpreters".
25
+
[smart header="Compilation and interpretation"]
26
+
There are in fact two general approaches to execute programs: "compilers" and "interpreters".
29
27
30
28
<ul>
31
-
<li>*Compilers* convert the program text (source code) to another language, usually machine language (binary code) without executing it. The binary code is then distributed to the system which runs it.</li>
32
-
<li>*Interpreters*, and in particular the one embedded in the browser -- get the source code and execute it "as is". The source code (script) is distributed to the system.</li>
29
+
<li>*Compilers* convert the program text (source code) to another language, usually the machine language (binary code) without executing it. This is done by the developer and then the binary code is distributed to the system which actually runs it.</li>
30
+
<li>*Interpreters*, and in particular the one embedded in the browser -- get the source code and execute it "as is". The source code (script) is distributed to the system as a plain text.</li>
33
31
</ul>
34
32
35
-
Modern interpreters actually convert the JavaScript to machine language or close to it, and then execute. That's why JavaScript is very fast.
33
+
Modern interpreters actually combine these approaches into one: the script is distributed as a plain text, but prior to execution is converted to the machine language. That's why JavaScript is very fast.
36
34
[/smart]
37
35
38
-
All major browsers have an embedded JavaScript interpreter, that's why they are capable of script execution.
39
-
40
-
But naturally JavaScript can be used not only in-browser. It's a full-fledged language usable at the server too and even in a washing machine if the interpreter is installed.
36
+
All major browsers have an embedded JavaScript interpreter, that's why they are capable of script execution. But naturally JavaScript can be used not only in-browser. It's a full-fledged language usable at the server too and even in a washing machine if it gets a chip with the interpreter installed.
41
37
42
-
[warn header="Let's talk browsers"]
38
+
[warn header="Let's talk about browsers"]
43
39
Further in the chapter we talk about capabilities and limitaitons of JavaScript in the browser.
44
40
[/warn]
45
41
46
42
## What JavaScript can do?
47
43
48
-
The modern JavaScript is a "safe" general purpose 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.
44
+
The 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.
49
45
50
46
Other capabilities depend on the environment which runs JavaScript. In the browser JavaScript is able to do everything related to webpage manipulation, talk to the visitor and, to some extent, talk to the internet.
51
47
52
-
Or, in more details:
48
+
Or, in more details, it is able to:
53
49
54
50
<ul>
55
-
<li>To create new HTML tags, remove the existing ones, change styles, hide/show elements...</li>
56
-
<li>To react on user actions, run on mouse clicks, pointer movements, key presses...</li>
57
-
<li>To send requests over the network to remote servers, download and upload data without reloading the page (a so-called "AJAX" technology)...</li>
58
-
<li>To get and set cookies, ask for data, show messages...</li>
59
-
<li>...and much much more!</li>
51
+
<li>Create new HTML tags, remove the existing ones, change styles, hide/show elements...</li>
52
+
<li>React on user actions, run on mouse clicks, pointer movements, key presses...</li>
53
+
<li>Send requests over the network to remote servers, download and upload data without reloading the page (a so-called "AJAX" technology)...</li>
54
+
<li>Get and set cookies, ask for data, show messages...</li>
55
+
<li>...and can do much more with the page and it's content!</li>
60
56
</ul>
61
57
62
58
## What JavaScript can NOT do?
63
59
64
60
JavaScript abilities in the browser are limited for user safety, mainly not to let an evil webpage access private information or harm the user's data.
65
61
66
-
Such limits do not exist if JavaScript is used outside of the browser, for example on server. Besides, modern browsers allow to install plugins and extensions which get extended permissions, but require actions from the user to accept that.
62
+
Such limits do not exist if JavaScript is used outside of the browser, for example on a server. Besides, modern browsers allow to install plugins and extensions which get extended permissions, but require actions from the user to accept that.
67
63
68
-
**JavaScript abilities are limited when it tries to access things outside of the current window/page.**
64
+
JavaScript abilities are also limited when it tries to access things outside of the current window/page.
69
65
70
-
<imgsrc="limitations.svg"width="530"height="400">
66
+
<imgsrc="limitations.svg">
71
67
72
68
<ul>
73
69
<li>JavaScript may not read/write arbitrary files on the hard disk, copy them or execute programs. It has no direct access to the OS.
74
70
75
-
Modern browsers allow it to work with files, but limit with a specially created directory called "a sandbox". There is a work going on to allow access to devices, the means are partially implemented in modern browsers.
71
+
Modern browsers allow it to work with files, but limit the access to a specially created directory called "a sandbox". There is a work going on to allow access to devices, with the user's permission.
76
72
</li>
77
73
<li>JavaScript from a browser tab may not access other tabs and windows with the exception when they were opened by this script and come from the same origin (domain, port, protocol).
78
74
79
75
There are ways to workaround this, and they are explained in the tutorial, but they require a special code on both documents which reside in different tabs/windows. Without it, for the sake of safety, JavaScript is disallowed to delve into another tab contents.
80
76
</li>
81
-
<li>JavaScript can easily send requests over the net to the server where the current page came from. But requests to other sites/domains are limited. Though possible, it requires the agreement (expressed in HTTP headers) from the remote side. That's less convenient, but again it's safety limitations.
77
+
<li>JavaScript can easily interact over the net to the server where the current page came from. But it's ability to receive data from other sites/domains is crippled. Though possible, it requires the explicit agreement (expressed in HTTP headers) from the remote side. Once again, that's safety limitations.
82
78
</li>
83
79
</ul>
84
80
85
81
## Why JavaScript is unique?
86
82
87
-
There are at least *three* great features in JavaScript:
83
+
There are at least *three* great things about JavaScript:
88
84
89
85
[compare]
90
86
+Full integration with HTML/CSS.
91
87
+Simple things done simply.
92
88
+Supported by all major browsers and enabled by default.
93
89
[/compare]
94
90
95
-
Combined, they only exist in JavaScript and no other browser technology.
91
+
Combined, these 3 things only exist in JavaScript and no other browser technology.
96
92
97
-
That makes JavaScript unique. That's why it is the most widespread way of creating browser interfaces.
93
+
That's what makes JavaScript unique. That's why it is the most widespread way of creating browser interfaces.
98
94
99
95
## The Trends
100
96
@@ -131,13 +127,13 @@ Modern browsers improve their engines to raise JavaScript execution script, fix
131
127
[summary]
132
128
The trend: JavaScript is becoming faster and more stable, gets new syntax.[/summary]
133
129
134
-
It's crucially important that new standards, HTML5, EcmaScript 6 are still compatible with the previous code, so there are no problems with the existing applications.
130
+
It's crucially important that new standards, HTML5, EcmaScript 6 are still compatible with the previous code, so there are introduced into the ecosystem without problems with the existing applications.
135
131
136
-
Still, there is a small gotcha with those "extra-fresh" modern browser abilities. Sometimes browsers try to implement them on very early stages when they are not fully described neither agreed upon, but still so interesting that the developers just can't wait.
132
+
Still, there is a small gotcha with those "extra-fresh" modern browser abilities. Sometimes browsers try to implement them on very early stages when they are nor fully defined neither agreed upon, but still are so interesting that the developers just can't wait.
137
133
138
-
...But as the time goes, the specification matures and changes, and browsers must adopt it. That may lead to errors in JavaScript code which was too eager to use the early browser implementation. So one should think twice before relying on things that are in draft yet.
134
+
...As the time goes, the specification matures and changes, and browsers must adapt it. That may lead to errors in JavaScript code which was too eager to use the early browser implementation. So one should think twice before relying on things that are in draft yet.
139
135
140
-
But what's great -- all browsers tend to follow the standard. There are much less differences between them now than only a couple years ago.
136
+
But what's great -- eventually all browsers tend to follow the standard. There are much less differences between them now than only a couple years ago.
141
137
142
138
[summary]
143
139
The trend: browsers, though eager for new features, become compatible with the standard.
@@ -155,28 +151,29 @@ Java is a widespread general-purpose language. For webpages, there is a special
155
151
*An applet* is a program written in Java language which can be attached to HTML using the `applet` tag, like this:
This tag loads the Java program from `BTApplet.class` and executes it with given parameters (`param`).
160
+
This tag loads the Java program from `MyApplet.class` and executes it with given parameters (`nodes`, `root`).
166
161
167
-
The applet runs in a rectangular part of the page, so called "container". All user actions inside it are processed by the applet, but only inside. One can hide the container if there's nothing to show.
162
+
The applet runs in a rectangular part of the page, so called "container". All user actions inside it are processed by the applet. One can hide the container if the applet does something not fit for the show.
168
163
169
164
Of course, Java runtime environment and the browser plugin must be installed and enabled to let the applet execute, and the applet itself must be signed by the publisher, otherwise it will be blocked.
170
165
171
-
**Why we, JavaScript-developers should be aware of Java?**
166
+
**Why us, JavaScript-developers should be aware of Java?**
172
167
173
-
Mainly because a signed Java-applet can do literally everything on a visitor's computer, just like any other program. Of course that requires a visitor's agreement to run it, but after that...
168
+
Mainly because a signed Java-applet can do literally everything on a visitor's computer, just like any other program. Of course that requires a visitor's agreement to run it, but after that they can break of any restrictions.
169
+
170
+
So if the user trusts as (like he's already a client of ours), we can implement something that pure javascript can't do yet.
174
171
175
172
Just to note, JavaScript and Java-applets can interact with each other, so JavaScript will have access to capabilities provided by the applet.
176
173
177
174
### Browser plugins and extensions
178
175
179
-
All modern browsers allow to write plugins using either JavaScript (Chrome, Opera, Firefox) and/or C language (ActiveX for Internet Explorer).
176
+
All modern browsers allow to write plugins using either JavaScript and/or C language.
180
177
181
178
The plugins can both handle a special kind of content (a media-player to play music) and interact with the page.
182
179
@@ -192,24 +189,24 @@ Flash is good at cross-browser device access: camera, microphone, and for certai
192
189
193
190
One can access Flash programs from JavaScript and vice versa.
194
191
195
-
The main drawback is that it needs Adobe Flash player to be installed and enabled. Users tend to disable it, because of nasty "multimedia" ads, certain devices like iPhonedo not support it. Besides, it is notorious for software vulnerabilities.
192
+
The main drawback is that it needs Adobe Flash player to be installed and enabled. Users tend to disable it, because of nasty "multimedia" ads and many vulnerabilities in the past. Also, certain operational systems like iOS (iPhone, iPad) do not support it at all.
196
193
197
194
## Languages over JavaScript
198
195
199
-
The syntax of JavaScript does not suit everyone's needs: some people think that it's too flexible, others consider it too limited, the third ones want to add new features absent in the standard...
196
+
The syntax of JavaScript does not suit everyone's needs: some people think that it's too flexible, the others consider it too limited, the third ones want to add new features absent in the standard...
200
197
201
-
That's normal, because projects and requirements are different for everyone.
198
+
That's normal, because projects and requirements are different for everyone. There's no a single standard for a carpenter's hammer, why should it exist for the language?
202
199
203
-
That's why a plethora of new languages appeared, which add features "over" JavaScript, meaning that the source code in these languages must be*transpiled* (converted) to JavaScript before they run.
200
+
So recently a plethora of new languages appeared, which add features "over" JavaScript, meaning that the source code in these languages is*transpiled* (converted) to JavaScript before they run.
204
201
205
-
The transpilation happens automatically, modern tools make it fully transparent, actually the process of development in these languages is very comfortable.
202
+
The transpilation happens automatically, modern tools make the process very fast and transparent, actually allowing developers to code in another language. They still should know JavaScript, to better understand what they are doing.
206
203
207
-
Just a few examples of such languages:
204
+
A few examples of such languages:
208
205
209
206
<ul>
210
207
<li>[CoffeeScript](http://coffeescript.org/) is a "syntax sugar" for JavaScript, it introduces shorter syntax, allowing to write more precise and clear code. Usually Ruby guys like it.</li>
211
208
<li>[TypeScript](http://www.typescriptlang.org/) is concentrated on adding "strict data typing", to simplify development and support of complex systems. Developed by Microsoft.</li>
212
-
<li>[Dart](https://www.dartlang.org/) was offered by Google as a replacement for JavaScript, but other leading internet companies declared that they are not interested. Maybe later it will shine, we'll see. Right now it can be transpiled to JavaScript.</li>
209
+
<li>[Dart](https://www.dartlang.org/) was offered by Google as a replacement for JavaScript, but other leading internet companies declared that they are not interested. Maybe later, we'll see. Right now it can be transpiled to JavaScript, but used less often compared to two previous alternatives.</li>
213
210
</ul>
214
211
215
212
[smart header="ES6 and ES7 right now"]
@@ -219,17 +216,15 @@ For those eager to use them now, there are transpilers which take the code writt
219
216
220
217
For example, [6to5](https://6to5.org/).
221
218
222
-
Thanks for them, many great syntax features are available already, even prior to the release.
219
+
Here in the first part of the tutorial I feel a little bit shy to use them, because without a native browser support such tools add unnecessary complexity at the start and can be easily integrated later when the basics are learned.
223
220
[/smart]
224
221
225
222
226
223
## Summary
227
224
228
-
Язык JavaScript уникален благодаря своей полной интеграции с HTML/CSS. Он работает почти у всех посетителей.
229
-
230
-
...Но хороший JavaScript-программист не должен забывать и о других технологиях.
225
+
JavaScript is unique due it's full integration with HTML/CSS and wide browser adoption.
231
226
232
-
Ведь наша цель -- создание хороших приложений, и здесь Flash, Java, ActiveX/NPAPI и браузерные расширения имеют свои уникальные возможности, которые можно использовать вместе с JavaScript.
227
+
...But a good JavaScript-developer should be aware of other technologies too. Our ultimate purpose is to create best frontend apps, and sometimes Java, Flash or plugins can be helpful too.
233
228
234
-
Что же касается CoffeeScript, TypeScript и других языков, построенных над JavaScript -- они могут быть очень полезны, рекомендуется посмотреть их, хотя бы в общих чертах, но, конечно, после освоения самого JavaScript.
229
+
Other languages like CoffeeScript and TypeScript can help to develop faster and write less bug-proof code. It is recommended to take a look at them, at least briefly, after mastering JavaScript.
0 commit comments