| | |
| | | </pre> |
| | | </section> |
| | | <section> |
| | | Lösung: Callback-Hell oder Pyramide des Todes |
| | | <pre> |
| | | <code class="js" data-trim data-line-numbers> |
| | | setTimeout(function() { |
| | | console.log("zweiter"); |
| | | |
| | | setTimeout(function() { |
| | | console.log("Text A"); |
| | | |
| | | setTimeout(function() { |
| | | console.log("Text B"); |
| | | |
| | | |
| | | }, 2000); |
| | | }, 2000); |
| | | }, 2000); |
| | | |
| | | console.log("erster"); |
| | | </code> |
| | | </pre> |
| | | </section> |
| | | <section> |
| | | Hilfsmittel: Promises |
| | | <pre> |
| | | <code class="js" data-trim data-line-numbers> |
| | |
| | | </pre> |
| | | </section> |
| | | <section> |
| | | Aufgabe: Implementiere die Funktion "delay", um die Promise-Kette lauffähig zu bekommen |
| | | Aufgabe: Implementiere die Funktion "delay" |
| | | <pre> |
| | | <code class="js" data-trim data-line-numbers> |
| | | const delay = function() { |
| | | // implementieren |
| | | } |
| | | |
| | | console.log("erster"); |
| | | |
| | | delay(2000) |
| | | .then(function () { |
| | | console.log("zweiter"); |
| | | |
| | | return delay(2000); |
| | | }) |
| | | .then(function() { |
| | | console.log("Text A"); |
| | | |
| | | return delay(2000); |
| | | }) |
| | | .then(function() { |
| | | console.log("Text B"); |
| | | }) |
| | | </code> |
| | | </pre> |
| | | </section> |
| | | </section> |
| | | </div> |