MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/javascript/comments/4s4ul0/the_javascript_language_reboot_is_done/d56u222/?context=3
r/javascript • u/velmu3k • Jul 10 '16
98 comments sorted by
View all comments
Show parent comments
0
[deleted]
4 u/konbit Jul 10 '16 edited Jul 10 '16 Here's my favorite:async function getPosts() { const res = await fetch('https://jsonplaceholder.typicode.com/posts'); const json = await res.json(); const posts = json.filter(obj => obj.userId === 1); console.log(`You have made ${posts.length} posts.`); }EDIT: res.json() is a promise 1 u/[deleted] Jul 10 '16 res.json() is also a promise, no? 1 u/konbit Jul 10 '16 Yup, fixed. Still an easier read. 1 u/[deleted] Jul 10 '16 I agree, never going back from async/await if I get to choose 1 u/[deleted] Jul 10 '16 Maybe const json = await fetch('https://jsonplaceholder.typicode.com/posts').then(res => res.json());?
4
Here's my favorite:
async function getPosts() { const res = await fetch('https://jsonplaceholder.typicode.com/posts'); const json = await res.json(); const posts = json.filter(obj => obj.userId === 1); console.log(`You have made ${posts.length} posts.`); }
EDIT: res.json() is a promise
1 u/[deleted] Jul 10 '16 res.json() is also a promise, no? 1 u/konbit Jul 10 '16 Yup, fixed. Still an easier read. 1 u/[deleted] Jul 10 '16 I agree, never going back from async/await if I get to choose 1 u/[deleted] Jul 10 '16 Maybe const json = await fetch('https://jsonplaceholder.typicode.com/posts').then(res => res.json());?
1
res.json() is also a promise, no?
1 u/konbit Jul 10 '16 Yup, fixed. Still an easier read. 1 u/[deleted] Jul 10 '16 I agree, never going back from async/await if I get to choose 1 u/[deleted] Jul 10 '16 Maybe const json = await fetch('https://jsonplaceholder.typicode.com/posts').then(res => res.json());?
Yup, fixed. Still an easier read.
1 u/[deleted] Jul 10 '16 I agree, never going back from async/await if I get to choose 1 u/[deleted] Jul 10 '16 Maybe const json = await fetch('https://jsonplaceholder.typicode.com/posts').then(res => res.json());?
I agree, never going back from async/await if I get to choose
Maybe const json = await fetch('https://jsonplaceholder.typicode.com/posts').then(res => res.json());?
const json = await fetch('https://jsonplaceholder.typicode.com/posts').then(res => res.json());
0
u/[deleted] Jul 10 '16
[deleted]