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
The [latest standard](http://www.ecma-international.org/publications/standards/Ecma-262.htm) was approved in June 2015.
5
5
6
-
As it includes a lot of new features, most browsers implement them partially. You can find the current state of the support at [](https://kangax.github.io/compat-table/es6/).
6
+
As it includes a lot of new features, most browsers implement them partially. You can find the current state of the support at <https://kangax.github.io/compat-table/es6/>.
7
7
8
8
## Single-engine app
9
9
@@ -13,7 +13,7 @@ Most notably, V8 supports many of the new features only if the code is running i
13
13
14
14
You will find most code in this tutorial using this directive and, because of that, runnable in Chrome.
15
15
16
-
But what if we're writing a cross-browser application? Different browsers support different subsets of ES-2015.
16
+
But what if we're writing a cross-browser application? Different browsers support different subsets of ES-2015.
17
17
18
18
Here comes Babel.JS.
19
19
@@ -23,30 +23,27 @@ Here comes Babel.JS.
23
23
24
24
Actually, there are two parts in Babel:
25
25
26
-
<ol>
27
-
<li>The transpiler program, which rewrites the code.
26
+
1. The transpiler program, which rewrites the code.
28
27
29
-
The transpiler runs on a developer's computer. It rewrites the code, which is then bundled by a project build system (like [webpack](http://webpack.github.io/) or [brunch](http://brunch.io/)). Most build systems can support Babel easily. One just needs to setup the build system itself.</li>
30
-
<li>JavaScript library.
28
+
The transpiler runs on a developer's computer. It rewrites the code, which is then bundled by a project build system (like [webpack](http://webpack.github.io/) or [brunch](http://brunch.io/)). Most build systems can support Babel easily. One just needs to setup the build system itself.
29
+
2.JavaScript library.
31
30
32
-
An additional JavaScript library with modern JavaScript functions for the browsers that do not have them built-in (yet). The library must be attached to each webpage which relies on these functions.</li>
33
-
</ol>
31
+
An additional JavaScript library with modern JavaScript functions for the browsers that do not have them built-in (yet). The library must be attached to each webpage which relies on these functions.
34
32
35
33
There is a special "play" mode of Babel.JS which merges both parts in a single in-browser script.
36
34
37
35
The usage looks like this:
38
36
39
-
```html
40
-
<!--+ run -->
37
+
```html run
41
38
*!*
42
39
<!-- browser.js is on my server please don't hotlink -->
@@ -57,16 +54,15 @@ Script `browser.min.js` is attached to the top of the page. It automatically tra
57
54
The size of `browser.min.js` is above 1 megabyte, because it includes the transpiler. Hence such usage is only for "playing" and not recommended for production.
58
55
59
56
Also:
60
-
<ul>
61
-
<li>There is a "try it" page on [](https://babeljs.io/repl/) which allows to run snippets of code.</li>
62
-
<li>[JSBin](http://jsbin.com) allows to use "ES6/Babel" mode for JS, see [this snippet](http://jsbin.com/daxihelolo/edit?js,output) as an example.</li>
63
-
</ul>
57
+
58
+
- There is a "try it" page on <https://babeljs.io/repl/> which allows to run snippets of code.
59
+
-[JSBin](http://jsbin.com) allows to use "ES6/Babel" mode for JS, see [this snippet](http://jsbin.com/daxihelolo/edit?js,output) as an example.
64
60
65
61
# Examples on this site
66
62
67
-
[warn header="Browser support is required"]
63
+
```warn header="Browser support is required"
68
64
Examples that use ES-2015 will work only if your browser supports it.
69
-
[/warn]
65
+
```
70
66
71
67
Sometimes it means that when running an example in a non-supporting browser, an error is shown.
72
68
@@ -80,7 +76,7 @@ And even if your browser does not support some code, you can run it through Babe
80
76
81
77
That would be fine, because on production everyone's using Babel anyway.
82
78
83
-
Once again, let's note that the most up-to-date situation with support is reflected on [](https://kangax.github.io/compat-table/es6/).
79
+
Once again, let's note that the most up-to-date situation with support is reflected on <https://kangax.github.io/compat-table/es6/>.
84
80
85
81
Now we can go coding, but we need a good code editor for that. That is discussed in the next session.
Copy file name to clipboardExpand all lines: 1-js/1-getting-started/3-editor/article.md
+16-23Lines changed: 16 additions & 23 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,12 +4,10 @@ For the comfortable development we need a good code editor.
4
4
5
5
It should support at least:
6
6
7
-
<ol>
8
-
<li>Syntax highlight.</li>
9
-
<li>Autocompletion.</li>
10
-
<li>Folding -- collapsing/opening blocks of code.</li>
11
-
<li>...the more features -- the better.</li>
12
-
</ol>
7
+
1. Syntax highlight.
8
+
2. Autocompletion.
9
+
3. Folding -- collapsing/opening blocks of code.
10
+
4. ...the more features -- the better.
13
11
14
12
[cut]
15
13
@@ -21,13 +19,11 @@ An IDE operates on a "whole project": loads it and then can navigate between fil
21
19
22
20
If you haven't considered selecting an IDE, pleae look at the following variants:
23
21
24
-
<ul>
25
-
<li>IntelliJ editors: [WebStorm](http://www.jetbrains.com/webstorm/) for frontend development and [PHPStorm (PHP)](http://www.jetbrains.com/phpstorm/), [IDEA (Java)](http://www.jetbrains.com/idea/), [RubyMine (Ruby)](http://www.jetbrains.com/ruby/) and other if you need additional languages.</li>
26
-
<li>Visual Studio is fine if you're a .NET developer.</li>
27
-
<li>Eclipse-based products, like [Aptana](http://www.aptana.com/) and Zend Studio.</li>
28
-
<li>[Komodo IDE](http://www.activestate.com/komodo-ide) and it's lightweight free version [Komodo Edit](http://www.activestate.com/komodo-edit).</li>
29
-
<li>[Netbeans](http://netbeans.org/)</li>
30
-
</ul>
22
+
- IntelliJ editors: [WebStorm](http://www.jetbrains.com/webstorm/) for frontend development and [PHPStorm (PHP)](http://www.jetbrains.com/phpstorm/), [IDEA (Java)](http://www.jetbrains.com/idea/), [RubyMine (Ruby)](http://www.jetbrains.com/ruby/) and other if you need additional languages.
23
+
- Visual Studio is fine if you're a .NET developer.
24
+
- Eclipse-based products, like [Aptana](http://www.aptana.com/) and Zend Studio.
25
+
-[Komodo IDE](http://www.activestate.com/komodo-ide) and it's lightweight free version [Komodo Edit](http://www.activestate.com/komodo-edit).
26
+
-[Netbeans](http://netbeans.org/)
31
27
32
28
All of them with the exception of Visual Studio are cross-platform.
33
29
@@ -45,22 +41,19 @@ In practice, "lightweight" editors may have a lot of plugins including directory
- Vim, Emacs are cool. If you know how to use them.
54
48
55
49
## My favorites
56
50
57
51
I believe one should have both an IDE for projects and a lightweight editor for quick and easy file editing.
58
52
59
53
I'm using:
60
-
<ul>
61
-
<li>[WebStorm](http://www.jetbrains.com/webstorm/) for JS, and if there is one more language in the project, then I switch to other Jetbrains editors like [PHPStorm](http://www.jetbrains.com/phpstorm/) (PHP), [IDEA](http://www.jetbrains.com/idea/) (Java), [RubyMine](http://www.jetbrains.com/ruby/) (Ruby). There are editors for other languages too, but I didn't use them.</li>
62
-
<li>As a lightweight editor -- <ahref="http://www.sublimetext.com">Sublime Text</a>.</li>
63
-
</ul>
54
+
55
+
-[WebStorm](http://www.jetbrains.com/webstorm/) for JS, and if there is one more language in the project, then I switch to other Jetbrains editors like [PHPStorm](http://www.jetbrains.com/phpstorm/) (PHP), [IDEA](http://www.jetbrains.com/idea/) (Java), [RubyMine](http://www.jetbrains.com/ruby/) (Ruby). There are editors for other languages too, but I didn't use them.
56
+
- As a lightweight editor -- <ahref="http://www.sublimetext.com">Sublime Text</a>.
64
57
65
58
If you don't know what to choose -- you can consider these ones.
Copy file name to clipboardExpand all lines: 1-js/1-getting-started/4-devtools/article.md
+13-18Lines changed: 13 additions & 18 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -20,53 +20,48 @@ Developer tools are really powerful, there are many features, but on this stage
20
20
21
21
[cut]
22
22
23
-
## Google Chrome
23
+
## Google Chrome
24
24
25
-
Open the page [bug.html](bug.html).
25
+
Open the page [bug.html](bug.html).
26
26
27
27
There's an error in the JavaScript code on it. An ordinary visitor won't see it, so let's open developer tools.
28
28
29
-
Press the key [keyF12] or, if you're on Mac, then [keyCmd+Opt+J].
29
+
Press the key `key:F12` or, if you're on Mac, then `key:Cmd+Opt+J`.
30
30
31
31
The developer tools will open on the Console tab by default.
32
32
33
33
It looks somewhat like this:
34
34
35
-
<imgsrc="chrome.png">
35
+

36
36
37
37
The exact look depends on your Chrome version. It changes from time to time, but should be similar.
38
38
39
-
<ul>
40
-
<li>Here we can see the red-colored error message. In this case the script contains a "lalala" command, which was put there just because it is unknown.</li>
41
-
<li>On the right, there is a clickable link to the source `bug.html:12` with the line number where the error has occured.</li>
42
-
</ul>
39
+
- Here we can see the red-colored error message. In this case the script contains a "lalala" command, which was put there just because it is unknown.
40
+
- On the right, there is a clickable link to the source `bug.html:12` with the line number where the error has occured.
43
41
44
-
Below the error message there is a blue `>` symbol. It marks a "command line" where we can type JavaScript commands and press enter to run them ([keyShift+Enter] to input multiline commands).
42
+
Below the error message there is a blue `>` symbol. It marks a "command line" where we can type JavaScript commands and press enter to run them (`key:Shift+Enter` to input multiline commands).
45
43
46
-
Now we can see errors and that's enough for the start. We'll be back to developer tools later and cover debugging more in-depth in the chapter [](/debugging-chrome).
44
+
Now we can see errors and that's enough for the start. We'll be back to developer tools later and cover debugging more in-depth in the chapter <info:debugging-chrome>.
47
45
48
46
## Safari
49
47
50
48
For Safari, we need to enable the "Develop menu" first.
51
49
52
50
There's a checkbox for that at the bottom of the "Advanced" pane of the preferences:
53
51
54
-
<imgsrc="safari.png">
52
+

55
53
56
-
Now [keyCmd+Opt+C] can toggle the console. Also note that the new top menu item has appeared with many useful options.
54
+
Now `key:Cmd+Opt+C` can toggle the console. Also note that the new top menu item has appeared with many useful options.
57
55
58
56
## Other browsers
59
57
60
-
Most other browsers use [keyF12] to open developer tools.
58
+
Most other browsers use `key:F12` to open developer tools.
61
59
62
60
The look & feel of them is quite similar, once we know how to use one of them (can start with Chrome), can easily switch to another.
63
61
64
62
## Summary
65
63
66
-
<ul>
67
-
<li>Developer tools allow us to see errors, run commands, examine variables and much more.</li>
68
-
<li>They can be opened with [key F12] for most browsers under Windows. Chrome for Mac needs [key Cmd+Opt+J], Safari: [key Cmd+Opt+C] (need to enable first).
69
-
</li>
70
-
</ul>
64
+
- Developer tools allow us to see errors, run commands, examine variables and much more.
65
+
- They can be opened with `key:F12` for most browsers under Windows. Chrome for Mac needs `key:Cmd+Opt+J`, Safari: `key:Cmd+Opt+C` (need to enable first).
71
66
72
67
Now we have the environment ready. In the next section we get down to JavaScript.
Copy file name to clipboardExpand all lines: 1-js/2-first-steps/1-hello-world/article.md
+27-36Lines changed: 27 additions & 36 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,20 +3,20 @@
3
3
In this chapter we'll create a simple script and see it working.
4
4
5
5
[cut]
6
+
6
7
## The "script" tag
7
8
8
-
[smart header="What if I want to move faster?"]
9
-
In the case if the reader of these lines has developed with JavaScript already or has a lot of experience in another language, he can skip detailed explanatins and jump to [](/javascript-specials). There he can find an essense of important features.
9
+
```smart header="What if I want to move faster?"
10
+
In the case if the reader of these lines has developed with JavaScript already or has a lot of experience in another language, he can skip detailed explanatins and jump to <info:javascript-specials>. There he can find an essense of important features.
10
11
11
12
If you have enough time and want to learn things in details then read on :)
12
-
[/smart]
13
+
```
13
14
14
15
JavaScript programs can be inserted in any place of HTML with the help of the `<script>` tag.
15
16
16
17
For instance:
17
18
18
-
```html
19
-
<!--+ run height=100 -->
19
+
```html run height=100
20
20
<!DOCTYPE HTML>
21
21
<html>
22
22
@@ -37,57 +37,48 @@ For instance:
37
37
</html>
38
38
```
39
39
40
-
[online]
40
+
```online
41
41
You can run the example clicking on a "Play" button in it's right-top corner.
42
-
[/online]
42
+
```
43
43
44
44
The `<script>` tag contains JavaScript code which is automatically executed when the browser meets the tag.
45
45
46
46
Please note the execution sequence:
47
47
48
-
<ol>
49
-
<li>Browser starts to parse the document and display the page.</li>
50
-
<li>When the browser meets `<script>`, it switches to the JavaScript execution mode. In this mode it executes the script.</li>
51
-
<li>The `alert` command shows a message and pauses the execution.</li>
52
-
<li>*Note that a part of the page before the script is shown already at this moment.*</li>
53
-
<li>When the script is finished, it gets back to the HTML-mode, and *only then* it shows the rest of the document.</li>
54
-
</ol>
48
+
1. Browser starts to parse the document and display the page.
49
+
2. When the browser meets `<script>`, it switches to the JavaScript execution mode. In this mode it executes the script.
50
+
3. The `alert` command shows a message and pauses the execution.
51
+
4.*Note that a part of the page before the script is shown already at this moment.*
52
+
5. When the script is finished, it gets back to the HTML-mode, and *only then* it shows the rest of the document.
55
53
56
54
A visitor won't see the content after the script until it is executed. In other words, a `<script>` tag blocks rendering.
57
55
58
-
59
56
## The modern markup
60
57
61
58
In the past, `<script>` had a few necessary attributes.
The `type` attribute: <code><script <u>type</u>=...></code>
67
63
68
-
<dd>The old standard HTML4 required a script to have the type. Usually it was `type="text/javascript"`. The modern HTML standard assumes this `type` by default, no attribute is required.
69
-
</dd>
64
+
: The old standard HTML4 required a script to have the type. Usually it was `type="text/javascript"`. The modern HTML standard assumes this `type` by default, no attribute is required.
<dd>This attribute was meant to show the language of the script. As of now, this attribute makes no sense, the language is JavaScript by default. No need to use it.</dd>
73
-
<dt>Comments before and after scripts.</dt>
74
-
<dd>In really ancient books and guides, one may find comments inside `<script>`, like this:
66
+
The `language` attribute: <code><script <u>language</u>=...></code>
67
+
: This attribute was meant to show the language of the script. As of now, this attribute makes no sense, the language is JavaScript by default. No need to use it.
75
68
76
-
```html
77
-
<!--+ no-beautify -->
78
-
<script type="text/javascript"><!--
79
-
...
80
-
//--></script>
81
-
```
69
+
Comments before and after scripts.
70
+
: In really ancient books and guides, one may find comments inside `<script>`, like this:
71
+
72
+
```html no-beautify
73
+
<script type="text/javascript"><!--
74
+
...
75
+
//--></script>
76
+
```
82
77
83
-
These comments were supposed to hide the code from an old browser that did't understand a `<script>` tag. But all browsers born in the past 15 years know about `<script>`, so that's not an issue. So if you see such code somewhere you know the guide is really old and probably not worth looking into.
84
-
</dd>
85
-
</dl>
78
+
These comments were supposed to hide the code from an old browser that did't understand a `<script>` tag. But all browsers born in the past 15 years know about `<script>`, so that's not an issue. So if you see such code somewhere you know the guide is really old and probably not worth looking into.
86
79
87
80
## Summary
88
81
89
-
<ul>
90
-
<li>We can use a `<script>` tag without attributes to add JavaScript code to the page.</li>
91
-
<li>A `<script>` tag blocks page rendering. Can be bad. Later we'll see how to evade that.</li>
92
-
</ul>
82
+
- We can use a `<script>` tag without attributes to add JavaScript code to the page.
83
+
- A `<script>` tag blocks page rendering. Can be bad. Later we'll see how to evade that.
0 commit comments