Skip to content

Commit 0ae3b38

Browse files
authored
Merge pull request #24 from javascript-tutorial/master
Update article.md
2 parents 75c9726 + 69f221f commit 0ae3b38

File tree

1 file changed

+48
-48
lines changed

1 file changed

+48
-48
lines changed
Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,91 +1,91 @@
11

2-
# Polyfilly a transpilery
2+
# Polyfills and transpilers
33

4-
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).
4+
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](http://www.ecma-international.org/publications/standards/Ecma-262.htm).
55

6-
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.
77

8-
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.
99

10-
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).
1111

12-
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!
1313

14-
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?
1515

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

18-
1. Transpilátory.
19-
2. Polyfilly.
18+
1. Transpilers.
19+
2. Polyfills.
2020

21-
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.
2222

23-
## Transpilátory
23+
## Transpilers
2424

25-
[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.
2626

27-
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`.
2828

29-
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`.
3030

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

35-
// po spuštění transpilátoru
36-
výška = (výška !== undefined && výška !== null) ? výška : 100;
35+
// after running the transpiler
36+
height = (height !== undefined && height !== null) ? height : 100;
3737
```
3838
39-
Nyní je přepsaný kód vhodný i pro starší JavaScriptové motory.
39+
Now the rewritten code is suitable for older JavaScript engines.
4040
41-
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.
4242
43-
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.
4444
45-
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.
4646
47-
## Polyfilly
47+
## Polyfills
4848
49-
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.
5050
51-
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`.
5252
53-
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.
5454
55-
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.
5656
57-
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.
5858
59-
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:
6060
6161
```js
62-
if (!Math.trunc) { // není-li taková funkce
63-
// implementuje ji
64-
Math.trunc = function(číslo) {
65-
// Math.ceil a Math.floor existují i v nejstarších JavaScriptových motorech
66-
// budou vysvětleny později v tomto tutoriálu
67-
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);
6868
};
6969
}
7070
```
7171
72-
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.
7373
74-
Dvě zajímavé knihovny polyfillů jsou:
75-
- [core js](https://github.com/zloirock/core-js), která toho podporuje mnoho a umožňuje přidávat jen potřebné vlastnosti.
76-
- [polyfill.io](http://polyfill.io) je služba, která poskytuje skript s polyfilly podle vlastností a uživatelova prohlížeče.
74+
Two interesting polyfill libraries are:
75+
- [core js](https://github.com/zloirock/core-js) that supports a lot, allows to include only needed features.
76+
- [polyfill.io](http://polyfill.io) service that provides a script with polyfills, depending on the features and user's browser.
7777
78-
## Shrnutí
7978
80-
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
8180
82-
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.
8382
84-
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.
8584
86-
Dobré zdroje, které ukazují aktuální stav podpory různých vlastností:
87-
- <https://kangax.github.io/compat-table/es6/> - pro čistý JavaScript.
88-
- <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.
8986
90-
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.
9190
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.

0 commit comments

Comments
 (0)