From 8eb52fb8ef05155cad8f1a1f2f65d10dc40a0c7f Mon Sep 17 00:00:00 2001 From: David Date: Tue, 15 Nov 2022 19:11:13 +0100 Subject: [PATCH] =?UTF-8?q?hinzugef=C3=BCgt=20Module=20Pattern,=20await=20?= =?UTF-8?q?und=20async=20Funtionen,=20verwendet=20json=20placeholder=20API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../chapter17/awaitMethod.js | 26 +++++++++++++++ .../Javascript Expert/chapter17/index.html | 2 +- .../chapter17/modulePattern.js | 33 +++++++++++++++++++ .../chapter17/shoppingCart.js | 3 ++ 4 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 javascript/Javascript Expert/chapter17/awaitMethod.js create mode 100644 javascript/Javascript Expert/chapter17/modulePattern.js diff --git a/javascript/Javascript Expert/chapter17/awaitMethod.js b/javascript/Javascript Expert/chapter17/awaitMethod.js new file mode 100644 index 0000000..dcebb77 --- /dev/null +++ b/javascript/Javascript Expert/chapter17/awaitMethod.js @@ -0,0 +1,26 @@ +import "./shoppingCart.js"; + +// console.log("Start fetching"); +// const response = await fetch("https://jsonplaceholder.typicode.com/posts"); + +// const data = await response.json(); +// console.log(data); +// console.log("Something"); + +const getLastPost = async function () { + const response = await fetch("https://jsonplaceholder.typicode.com/posts"); + const data = await response.json(); + console.log(data); + + return { title: data.at(-1).title, text: data.at(-1).body }; +}; + +const lastPost = getLastPost(); +console.log(lastPost); + +lastPost.then(function (last) { + console.log(last); +}); + +const lastPost2 = await getLastPost(); +console.log(lastPost2); diff --git a/javascript/Javascript Expert/chapter17/index.html b/javascript/Javascript Expert/chapter17/index.html index 6b4c3f1..7c3ba46 100644 --- a/javascript/Javascript Expert/chapter17/index.html +++ b/javascript/Javascript Expert/chapter17/index.html @@ -4,7 +4,7 @@ - + Modern JavaScript Development: Modules and Tooling