Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Promises chaining#194

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
otmon76 merged 2 commits intojavascript-tutorial:masterfromotmon76:1.11.3
Jun 4, 2025
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
The short answer is: **no, they are not equal**:
Stručná odpověď zní: **ne, nejsou ekvivalentní**:

The difference is that if an error happens in`f1`, then it is handled by`.catch` here:
Rozdíl je v tom, že pokud ve`f1` nastane chyba, je zde ošetřena funkcí`.catch`:

```js run
promise
příslib
.then(f1)
.catch(f2);
```

...But not here:
...Ale zde ne:

```js run
promise
příslib
.then(f1, f2);
```

That's because an error is passed down the chain, and in the second code piece there's no chain below`f1`.
Je to proto, že chyba je předána řetězem, ale ve druhém uvedeném kódu za`f1` žádný řetěz není.

In other words, `.then`passes results/errors to the next `.then/catch`.So in the first example, there's a`catch` below, and in the second one there isn't, so the error is unhandled.
Jinými slovy, `.then`předá výsledky nebo chyby dalšímu `.then/catch`.V prvním příkladu je za ním`catch`, ale ve druhém není, takže chyba zůstane neošetřena.
10 changes: 5 additions & 5 deletions1-js/11-async/03-promise-chaining/01-then-vs-catch/task.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
#Promise: thenversus catch
#Příslib: thenoproti catch

Are these code fragments equal? In other words, do they behave the same way in any circumstances, for any handler functions?
Jsou tyto fragmenty kódu ekvivalentní? Jinými slovy, chovají se zcela stejně za každých okolností a pro jakékoli handlery?

```js
promise.then(f1).catch(f2);
příslib.then(f1).catch(f2);
```

Versus:
Oproti:

```js
promise.then(f1, f2);
příslib.then(f1, f2);
```
374 changes: 187 additions & 187 deletions1-js/11-async/03-promise-chaining/article.md
View file
Open in desktop

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions1-js/11-async/03-promise-chaining/head.html
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
<script>
functionloadScript(src) {
functionnačtiSkript(src) {
return new Promise(function(resolve, reject) {
letscript = document.createElement('script');
script.src = src;
letskript = document.createElement('script');
skript.src = src;

script.onload = () => resolve(script);
script.onerror = () => reject(new Error("Script load error: " + src));
skript.onload = () => resolve(skript);
skript.onerror = () => reject(new Error("Chyba při načítání skriptu: " + src));

document.head.append(script);
document.head.append(skript);
});
}
</script>
Expand Down
2 changes: 1 addition & 1 deletion1-js/11-async/03-promise-chaining/one.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
functionone() {
functionjedna() {
alert(1);
}
View file
Open in desktop
Loading
Sorry, something went wrong.Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

[8]ページ先頭

©2009-2025 Movatter.jp