Skip to content

Commit 6aa5018

Browse files
authored
Merge pull request #68 from otmon76/2.3
2.3
2 parents c575fbb + e38821a commit 6aa5018

File tree

1 file changed

+37
-41
lines changed

1 file changed

+37
-41
lines changed
Lines changed: 37 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,89 +1,85 @@
1-
# The modern mode, "use strict"
1+
# Moderní režim, „use strict
22

3-
For a long time, JavaScript evolved without compatibility issues. New features were added to the language while old functionality didn't change.
3+
Dlouhou dobu byl JavaScript vyvíjen bez problémů s kompatibilitou. Do jazyka byly přidávány nové prvky, zatímco stará funkcionalita se neměnila.
44

5-
That had the benefit of never breaking existing code. But the downside was that any mistake or an imperfect decision made by JavaScript's creators got stuck in the language forever.
5+
Mělo to tu výhodu, že se nerozbíjel již existující kód. Nevýhodou však bylo, že každá chyba nebo nedokonalé rozhodnutí tvůrců JavaScriptu zůstala v jazyce zakotvena navždy.
66

7-
This was the case until 2009 when ECMAScript 5 (ES5) appeared. It added new features to the language and modified some of the existing ones. To keep the old code working, most such modifications are off by default. You need to explicitly enable them with a special directive: `"use strict"`.
7+
To platilo až do roku 2009, kdy se objevil ECMAScript 5 (ES5), který do jazyka přidal nové vlastnosti a upravil některé již existující. Aby starý kód nepřestal fungovat, většina těchto úprav je defaultně vypnuta. Musíte je výslovně povolit speciální direktivou: `"use strict"`.
88

9-
## "use strict"
9+
## use strict
1010

11-
The directive looks like a string: `"use strict"` or `'use strict'`. When it is located at the top of a script, the whole script works the "modern" way.
11+
Tato direktiva má podobu řetězce: `"use strict"` nebo `'use strict'`. Když je umístěna na začátku skriptu, celý skript bude fungovat „moderním“ způsobem.
1212

13-
For example:
13+
Příklad:
1414

1515
```js
1616
"use strict";
1717

18-
// this code works the modern way
18+
// tento kód funguje moderním způsobem
1919
...
2020
```
2121

22-
Quite soon we're going to learn functions (a way to group commands), so let's note in advance that `"use strict"` can be put at the beginning of a function. Doing that enables strict mode in that function only. But usually people use it for the whole script.
22+
Brzy se naučíme používat funkce (způsob, jak seskupit příkazy), a tak s předstihem zmíníme, že `"use strict"` můžeme umístit i na začátek funkce. Když to uděláme, umožníme striktní režim pouze v této funkci. Většinou jej však lidé používají pro celý skript.
2323

24-
````warn header="Ensure that \"use strict\" is at the top"
25-
Please make sure that `"use strict"` is at the top of your scripts, otherwise strict mode may not be enabled.
24+
````warn header="Zajistěte, aby „use strict“ bylo na začátku"
25+
Zajistěte, aby `"use strict"` bylo hned na samém začátku vašeho skriptu, jinak nebude striktní režim povolen.
2626
27-
Strict mode isn't enabled here:
27+
Zde není striktní režim povolen:
2828
2929
```js no-strict
30-
alert("some code");
31-
// "use strict" below is ignored--it must be at the top
30+
alert("nějaký kód");
31+
// níže uvedený "use strict" se ignoruje -- musí být na začátku
3232
3333
"use strict";
3434
35-
// strict mode is not activated
35+
// striktní režim není aktivován
3636
```
3737
38-
Only comments may appear above `"use strict"`.
38+
Nad `"use strict"` nesmí být nic jiného než komentáře.
3939
````
4040

41-
```warn header="There's no way to cancel `use strict`"
42-
There is no directive like `"no use strict"` that reverts the engine to old behavior.
43-
44-
Once we enter strict mode, there's no going back.
41+
```warn header="`use strict` nelze nijak zrušit"
42+
Neexistuje žádná direktiva jako `"no use strict"`, která by vrátila motoru výchozí chování. Jakmile jednou vstoupíme do striktního režimu, už není cesty zpět.
4543
```
4644
47-
## Browser console
48-
49-
When you use a [developer console](info:devtools) to run code, please note that it doesn't `use strict` by default.
45+
## Prohlížečová konzole
5046
51-
Sometimes, when `use strict` makes a difference, you'll get incorrect results.
47+
Když spustíte kód ve [vývojářské konzoli](info:devtools), neběží automaticky ve striktním režimu.
48+
Někdy to může ovlivnit i samotný výsledek.
5249
53-
So, how to actually `use strict` in the console?
50+
Jak tedy vlastně používat `use strict` v konzoli?
5451
55-
First, you can try to press `key:Shift+Enter` to input multiple lines, and put `use strict` on top, like this:
52+
Můžete zkusit vložit více řádků pomocí zkratky `key:Shift+Enter` a umístit `use strict` na začátek, například takto:
5653
5754
```js
58-
'use strict'; <Shift+Enter for a newline>
59-
// ...your code
60-
<Enter to run>
55+
'use strict'; <Shift+Enter pro nový řádek>
56+
// ...váš kód
57+
<Enter pro spuštění>
6158
```
6259

63-
It works in most browsers, namely Firefox and Chrome.
60+
Funguje to ve většině prohlížečů, konkrétně ve Firefoxu a Chrome.
6461

65-
If it doesn't, e.g. in an old browser, there's an ugly, but reliable way to ensure `use strict`. Put it inside this kind of wrapper:
62+
Pokud to nefunguje, např. v nějakém starém prohlížeči, existuje jeden nepěkný, ale spolehlivý způsob, jak zajistit `use strict`. Umístěte jej do tohoto obalu:
6663

6764
```js
6865
(function() {
6966
'use strict';
7067

71-
// ...your code here...
68+
// ...zde je váš kód...
7269
})()
7370
```
7471

75-
## Should we "use strict"?
76-
77-
The question may sound obvious, but it's not so.
72+
## Měli bychom používat „use strict“?
7873

79-
One could recommend to start scripts with `"use strict"`... But you know what's cool?
74+
Odpověď na tuto otázku se může zdát samozřejmá, ale není tomu tak.
8075

81-
Modern JavaScript supports "classes" and "modules" - advanced language structures (we'll surely get to them), that enable `use strict` automatically. So we don't need to add the `"use strict"` directive, if we use them.
76+
Můžeme vám doporučit, abyste zahajovali skripty s `"use strict"`... ale víte, co je fajn?
8277

83-
**So, for now `"use strict";` is a welcome guest at the top of your scripts. Later, when your code is all in classes and modules, you may omit it.**
78+
Moderní JavaScript podporuje „třídy“ a „moduly“ – pokročilé jazykové struktury (určitě se k nim dostaneme), které používají `use strict` automaticky. Pokud je tedy používáme, nemusíme direktivu `use strict` přidávat.
8479

85-
As of now, we've got to know about `use strict` in general.
80+
**Prozatím tedy `"use strict"` používejte; na začátku vašich skriptů bývá vítaným hostem. Později, až budete mít celý svůj kód v třídách a modulech, jej můžete vypustit.**
8681

87-
In the next chapters, as we learn language features, we'll see the differences between the strict and old modes. Luckily, there aren't many and they actually make our lives better.
82+
Prozatím tedy víme, jak obecně `use strict` používat.
83+
Až se v dalších kapitolách naučíme další vlastnosti jazyka, poznáme rozdíly mezi striktním a starším režimem. Naštěstí jich není mnoho a ve skutečnosti nám spíše ulehčují práci.
8884

89-
All examples in this tutorial assume strict mode unless (very rarely) specified otherwise.
85+
Všechny příklady v našem tutoriálu předpokládají striktní režim, pokud není (velmi zřídka) uvedeno jinak.

0 commit comments

Comments
 (0)