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

Promise#193

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.2
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
4 changes: 2 additions & 2 deletions1-js/11-async/02-promise-basics/01-re-resolve/solution.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
The output is: `1`.
Výstup je: `1`.

The second call to `resolve` is ignored, because only the first call of `reject/resolve` is taken into account. Further calls are ignored.
Druhé volání `splň` se ignoruje, protože v úvahu se bere vždy jen první volání `splň/zamítni`. Další volání jsou ignorována.
12 changes: 6 additions & 6 deletions1-js/11-async/02-promise-basics/01-re-resolve/task.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@

#Re-resolve a promise?
#Znovusplnění příslibu?


What's the output of the code below?
Jaký je výstup následujícího kódu?

```js
letpromise = new Promise(function(resolve, reject) {
resolve(1);
letpříslib = new Promise(function(splň, zamítni) {
splň(1);

setTimeout(() =>resolve(2), 1000);
setTimeout(() =>splň(2), 1000);
});

promise.then(alert);
příslib.then(alert);
```
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
```js run
functiondelay(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
functiončekej(ms) {
return new Promise(splň => setTimeout(splň, ms));
}

delay(3000).then(() => alert('runs after 3 seconds'));
čekej(3000).then(() => alert('spustí se za 3 sekundy'));
```

Please note that in this task `resolve` is called without arguments. We don't return any value from `delay`, just ensure the delay.
Prosíme všimněte si, že v této úloze je `splň` voláno bez argumentů. Z funkce `čekej` nevracíme žádnou hodnotu, jen zajistíme čekání.
12 changes: 6 additions & 6 deletions1-js/11-async/02-promise-basics/02-delay-promise/task.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@

#Delay with a promise
#Čekání s příslibem

The built-in function`setTimeout`uses callbacks. Create a promise-based alternative.
Vestavěná funkce`setTimeout`používá callbacky. Vytvořte alternativu založenou na příslibech.

The function `delay(ms)`should return a promise. That promise should resolve after`ms`milliseconds, so that we can add `.then` to it, like this:
Funkce `čekej(ms)`by měla vrátit příslib. Tento příslib by se měl splnit za`ms`milisekund, takže do něj můžeme přidat `.then`, například:

```js
functiondelay(ms) {
//your code
functiončekej(ms) {
//váš kód
}

delay(3000).then(() => alert('runs after 3 seconds'));
čekej(3000).then(() => alert('spustí se za 3 sekundy'));
```
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -22,18 +22,18 @@

<body>

<button onclick="go()">Click me</button>
<button onclick="spusť()">Klikni na mne</button>

<script>

functiongo() {
showCircle(150, 150, 100).then(div => {
functionspusť() {
zobrazKruh(150, 150, 100).then(div => {
div.classList.add('message-ball');
div.append("Hello, world!");
div.append("Ahoj, světe!");
});
}

functionshowCircle(cx, cy,radius) {
functionzobrazKruh(cx, cy,poloměr) {
let div = document.createElement('div');
div.style.width = 0;
div.style.height = 0;
Expand All@@ -44,8 +44,8 @@

return new Promise(resolve => {
setTimeout(() => {
div.style.width =radius * 2 + 'px';
div.style.height =radius * 2 + 'px';
div.style.width =poloměr * 2 + 'px';
div.style.height =poloměr * 2 + 'px';

div.addEventListener('transitionend', function handler() {
div.removeEventListener('transitionend', handler);
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@

#Animated circle with promise
#Animovaný kruh s příslibem

Rewrite the `showCircle` function in the solution of the task<info:task/animate-circle-callback>so that it returns a promise instead of accepting a callback.
Přepište funkci `zobrazKruh` v řešení úlohy<info:task/animate-circle-callback>tak, aby místo přijímání callbacku vracela příslib.

The new usage:
Nové použití:

```js
showCircle(150, 150, 100).then(div => {
zobrazKruh(150, 150, 100).then(div => {
div.classList.add('message-ball');
div.append("Hello, world!");
div.append("Ahoj, světe!");
});
```

Take the solution of the task<info:task/animate-circle-callback> as the base.
Jako základ vezměte řešení úlohy<info:task/animate-circle-callback>.
357 changes: 179 additions & 178 deletions1-js/11-async/02-promise-basics/article.md
View file
Open in desktop

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions1-js/11-async/02-promise-basics/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>
2 changes: 1 addition & 1 deletion1-js/11-async/02-promise-basics/promise-reject-1.svg
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.
2 changes: 1 addition & 1 deletion1-js/11-async/02-promise-basics/promise-resolve-1.svg
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.
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.

[8]ページ先頭

©2009-2025 Movatter.jp