Skip to content

Commit c79a27f

Browse files
authored
Merge pull request #85 from javascript-tutorial/revert-68-2.3
Revert "2.3"
2 parents 8616ef2 + ccd8945 commit c79a27f

File tree

1 file changed

+41
-37
lines changed

1 file changed

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

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.
3+
For a long time, JavaScript evolved without compatibility issues. New features were added to the language while old functionality didn't change.
44

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.
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.
66

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"`.
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"`.
88

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

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.
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.
1212

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

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

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

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.
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.
2323

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.
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.
2626
27-
Zde není striktní režim povolen:
27+
Strict mode isn't enabled here:
2828
2929
```js no-strict
30-
alert("nějaký kód");
31-
// níže uvedený "use strict" se ignoruje -- musí být na začátku
30+
alert("some code");
31+
// "use strict" below is ignored--it must be at the top
3232
3333
"use strict";
3434
35-
// striktní režim není aktivován
35+
// strict mode is not activated
3636
```
3737
38-
Nad `"use strict"` nesmí být nic jiného než komentáře.
38+
Only comments may appear above `"use strict"`.
3939
````
4040

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.
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.
4345
```
4446
45-
## Prohlížečová konzole
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.
4650
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.
51+
Sometimes, when `use strict` makes a difference, you'll get incorrect results.
4952
50-
Jak tedy vlastně používat `use strict` v konzoli?
53+
So, how to actually `use strict` in the console?
5154
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:
55+
First, you can try to press `key:Shift+Enter` to input multiple lines, and put `use strict` on top, like this:
5356
5457
```js
55-
'use strict'; <Shift+Enter pro nový řádek>
56-
// ...váš kód
57-
<Enter pro spuštění>
58+
'use strict'; <Shift+Enter for a newline>
59+
// ...your code
60+
<Enter to run>
5861
```
5962

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

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:
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:
6366

6467
```js
6568
(function() {
6669
'use strict';
6770

68-
// ...zde je váš kód...
71+
// ...your code here...
6972
})()
7073
```
7174

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

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

76-
Můžeme vám doporučit, abyste zahajovali skripty s `"use strict"`... ale víte, co je fajn?
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.
7782

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.
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.**
7984

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.**
85+
As of now, we've got to know about `use strict` in general.
8186

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.
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.
8488

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

0 commit comments

Comments
 (0)