Skip to content

Commit 3417ea0

Browse files
authored
English version restored because it's not revided yet
1 parent 52ed344 commit 3417ea0

File tree

1 file changed

+45
-54
lines changed

1 file changed

+45
-54
lines changed
Lines changed: 45 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,101 +1,92 @@
11

2-
# Polyfilly a transpilátory
2+
# Polyfills and transpilers
33

4-
<<<<<<< HEAD
5-
Jazyk JavaScript se neustále vyvíjí. Pravidelně se pro tento jazyk objevují nové návrhy, ty jsou analyzovány a jsou-li shledány užitečnými, přidají se na seznam na <https://tc39.github.io/ecma262/> a pak pokračují do [specifikace](http://www.ecma-international.org/publications/standards/Ecma-262.htm).
6-
=======
74
The JavaScript language steadily evolves. New proposals to the language appear regularly, they are analyzed and, if considered worthy, are appended to the list at <https://tc39.github.io/ecma262/> and then progress to the [specification](https://www.ecma-international.org/publications-and-standards/standards/ecma-262/).
8-
>>>>>>> 746ad803c878e33182e7fab1578c0d15b9b75ca0
95

10-
Týmy vyvíjející JavaScriptové motory mají své vlastní nápady ohledně toho, co implementovat jako první. Mohou se rozhodnout implementovat návrhy, které jsou teprve načrtnuty, a odložit věci, které jsou už ve specifikaci, protože jsou méně zajímavé nebo prostě jen těžší na implementaci.
6+
Teams behind JavaScript engines have their own ideas about what to implement first. They may decide to implement proposals that are in draft and postpone things that are already in the spec, because they are less interesting or just harder to do.
117

12-
Je tedy poměrně běžné, že motor implementuje pouze část standardu.
8+
So it's quite common for an engine to implement only part of the standard.
139

14-
Dobrá stránka, na které uvidíte aktuální stav podpory vlastností jazyka, je <https://kangax.github.io/compat-table/es6/> (je to velká tabulka, máme ještě hodně co studovat).
10+
A good page to see the current state of support for language features is <https://kangax.github.io/compat-table/es6/> (it's big, we have a lot to study yet).
1511

16-
Jako programátoři rádi používáme nejnovější vlastnosti. Čím více dobrých věcí, tím lépe!
12+
As programmers, we'd like to use most recent features. The more good stuff - the better!
1713

18-
Na druhou stranu, jak přimět náš moderní kód, aby fungoval na starších motorech, které ještě nerozumějí vlastnostem přidaným teprve nedávno?
14+
On the other hand, how to make our modern code work on older engines that don't understand recent features yet?
1915

20-
Jsou dva druhy nástrojů, které to zajistí:
16+
There are two tools for that:
2117

22-
1. Transpilátory.
23-
2. Polyfilly.
18+
1. Transpilers.
19+
2. Polyfills.
2420

25-
V této kapitole je naším cílem získat náhled na to, jak fungují a jaké je jejich místo při vývoji webů.
21+
Here, in this chapter, our purpose is to get the gist of how they work, and their place in web development.
2622

27-
## Transpilátory
23+
## Transpilers
2824

29-
[Transpilátor](https://cs.wikipedia.org/wiki/Transpiler) neboli transpiler je zvláštní druh softwaru, který překládá zdrojový kód do jiného zdrojového kódu. Umí parsovat („přečíst a pochopit“) moderní kód a přepsat jej pomocí starších syntaktických konstrukcí tak, aby kód fungoval i na zastaralých motorech.
25+
A [transpiler](https://en.wikipedia.org/wiki/Source-to-source_compiler) is a special piece of software that translates source code to another source code. It can parse ("read and understand") modern code and rewrite it using older syntax constructs, so that it'll also work in outdated engines.
3026

31-
Například JavaScript před rokem 2020 neměl „operátor koalescence“ `??`. Jestliže tedy návštěvník používá zastaralý prohlížeč, nemusí porozumět kódu `výška = výška ?? 100`.
27+
E.g. JavaScript before year 2020 didn't have the "nullish coalescing operator" `??`. So, if a visitor uses an outdated browser, it may fail to understand the code like `height = height ?? 100`.
3228

33-
Transpilátor analyzuje náš kód a přepíše `výška ?? 100` na `(výška !== undefined && výška !== null) ? výška : 100`.
29+
A transpiler would analyze our code and rewrite `height ?? 100` into `(height !== undefined && height !== null) ? height : 100`.
3430

3531
```js
36-
// před spuštěním transpilátoru
37-
výška = výška ?? 100;
32+
// before running the transpiler
33+
height = height ?? 100;
3834

39-
// po spuštění transpilátoru
40-
výška = (výška !== undefined && výška !== null) ? výška : 100;
35+
// after running the transpiler
36+
height = (height !== undefined && height !== null) ? height : 100;
4137
```
4238
43-
Nyní je přepsaný kód vhodný i pro starší JavaScriptové motory.
39+
Now the rewritten code is suitable for older JavaScript engines.
4440
45-
Vývojář si obvykle spustí transpilátor na svém vlastním počítači a pak zveřejní transpilovaný kód na serveru.
41+
Usually, a developer runs the transpiler on their own computer, and then deploys the transpiled code to the server.
4642
47-
Když hovoříme o názvech, jedním z nejvýznamnějších transpilátorů je [Babel](https://babeljs.io).
43+
Speaking of names, [Babel](https://babeljs.io) is one of the most prominent transpilers out there.
4844
49-
Moderní systémy pro vytváření projektů, například [webpack](https://webpack.js.org/), poskytují způsoby, jak spouštět transpilátor automaticky při každé změně kódu, takže je velmi jednoduché jej integrovat do procesu vývoje.
45+
Modern project build systems, such as [webpack](https://webpack.js.org/), provide a means to run a transpiler automatically on every code change, so it's very easy to integrate into the development process.
5046
51-
## Polyfilly
47+
## Polyfills
5248
53-
Mezi nové vlastnosti jazyka mohou patřit nejenom syntaktické konstrukce a operátory, ale také vestavěné funkce.
49+
New language features may include not only syntax constructs and operators, but also built-in functions.
5450
55-
Například `Math.trunc(n)` je funkce, která „odřízne“ desetinnou část čísla, např. `Math.trunc(1.23)` vrátí `1`.
51+
For example, `Math.trunc(n)` is a function that "cuts off" the decimal part of a number, e.g `Math.trunc(1.23)` returns `1`.
5652
57-
V některých (velmi zastaralých) JavaScriptových motorech není funkce `Math.trunc`, takže takový kód selže.
53+
In some (very outdated) JavaScript engines, there's no `Math.trunc`, so such code will fail.
5854
59-
Protože hovoříme o nových funkcích a ne o syntaktických změnách, není tady potřeba nic transpilovat. Potřebujeme jenom deklarovat chybějící funkci.
55+
As we're talking about new functions, not syntax changes, there's no need to transpile anything here. We just need to declare the missing function.
6056
61-
Skript, který vylepšuje nebo přidává nové funkce, se nazývá „polyfill“. „Vyplní“ (anglicky „fill in“) mezeru a přidá chybějící implementace.
57+
A script that updates/adds new functions is called "polyfill". It "fills in" the gap and adds missing implementations.
6258
63-
V tomto konkrétním případě je polyfill pro `Math.trunc` skript, který ji implementuje, například takto:
59+
For this particular case, the polyfill for `Math.trunc` is a script that implements it, like this:
6460
6561
```js
66-
if (!Math.trunc) { // není-li taková funkce
67-
// implementuje ji
68-
Math.trunc = function(číslo) {
69-
// Math.ceil a Math.floor existují i v nejstarších JavaScriptových motorech
70-
// budou vysvětleny později v tomto tutoriálu
71-
return číslo < 0 ? Math.ceil(číslo) : Math.floor(číslo);
62+
if (!Math.trunc) { // if no such function
63+
// implement it
64+
Math.trunc = function(number) {
65+
// Math.ceil and Math.floor exist even in ancient JavaScript engines
66+
// they are covered later in the tutorial
67+
return number < 0 ? Math.ceil(number) : Math.floor(number);
7268
};
7369
}
7470
```
7571
76-
JavaScript je vysoce dynamický jazyk. Skripty mohou přidávat nebo modifikovat libovolné funkce, dokonce i vestavěné.
72+
JavaScript is a highly dynamic language. Scripts may add/modify any function, even built-in ones.
7773
78-
<<<<<<< HEAD
79-
Dvě zajímavé knihovny polyfillů jsou:
80-
- [core js](https://github.com/zloirock/core-js), která toho podporuje mnoho a umožňuje přidávat jen potřebné vlastnosti.
81-
- [polyfill.io](http://polyfill.io) je služba, která poskytuje skript s polyfilly podle vlastností a uživatelova prohlížeče.
82-
=======
8374
Two interesting polyfill libraries are:
8475
- [core js](https://github.com/zloirock/core-js) that supports a lot, allows to include only needed features.
8576
- [polyfill.io](https://polyfill.io/) service that provides a script with polyfills, depending on the features and user's browser.
86-
>>>>>>> 746ad803c878e33182e7fab1578c0d15b9b75ca0
8777
88-
## Shrnutí
8978
90-
V této kapitole jsme vás chtěli motivovat k prostudování moderních vlastností jazyka, včetně těch „za hranou“, i když ještě nejsou příliš podporovány v motorech JavaScriptu.
79+
## Summary
9180
92-
Jen nezapomínejte používat transpilátor (používáte-li moderní syntaxi nebo operátory) a polyfilly (abyste přidali funkce, které mohou chybět). Ty zajistí, že váš kód bude fungovat.
81+
In this chapter we'd like to motivate you to study modern and even "bleeding-edge" language features, even if they aren't yet well-supported by JavaScript engines.
9382
94-
Například později, až budete JavaScript dobře znát, si můžete nastavit systém pro vytváření kódu založený na [webpacku](https://webpack.js.org/) s pluginem [babel-loader](https://github.com/babel/babel-loader).
83+
Just don't forget to use a transpiler (if using modern syntax or operators) and polyfills (to add functions that may be missing). They'll ensure that the code works.
9584
96-
Dobré zdroje, které ukazují aktuální stav podpory různých vlastností:
97-
- <https://kangax.github.io/compat-table/es6/> - pro čistý JavaScript.
98-
- <https://caniuse.com/> - pro funkce vztahující se k prohlížeči.
85+
For example, later when you're familiar with JavaScript, you can setup a code build system based on [webpack](https://webpack.js.org/) with the [babel-loader](https://github.com/babel/babel-loader) plugin.
9986
100-
P.S. Pokud se týká vlastností jazyka, obvykle je nejaktuálnější Google Chrome. Pokud vám některé demo v tomto tutoriálu selže, zkuste ho. Většina dem v tutoriálu však funguje na kterémkoli moderním prohlížeči.
87+
Good resources that show the current state of support for various features:
88+
- <https://kangax.github.io/compat-table/es6/> - for pure JavaScript.
89+
- <https://caniuse.com/> - for browser-related functions.
90+
91+
P.S. Google Chrome is usually the most up-to-date with language features, try it if a tutorial demo fails. Most tutorial demos work with any modern browser though.
10192

0 commit comments

Comments
 (0)