The ninja code section is pure sarcasm, right? I'm not sure now which sections are and aren't.
A Modern JavaScript Tutorial
11–20 of 299 posts
Re: A Modern JavaScript Tutorial
#12The default way promises are used is now async/await. `.then()` should not be introduced as anything more than 'you may find this in older codebases'.
Can you point to anything other than saying "this is obvious"?
Here's a simple question to ask yourself: what if non-IO operations allowed you to use the .then() syntax? If you have the choice to use:
1 + 1.then(function(result) { ... }
vs const result = 1 + 1
Which would you choose?Re: A Modern JavaScript Tutorial
#13The default way promises are used is now async/await. `.then()` should not be introduced as anything more than 'you may find this in older codebases'.
Re: A Modern JavaScript Tutorial
#14Earlier quoted context omitted.
Can you point to anything other than saying "this is obvious"?
No, just experience with a lot of codebases. Here's a simple question to ask yourself: what if non-IO operations allowed you to use the .then() syntax? If you have the choice to use: 1 + 1.then(function(result) { ... } vs const result = 1 + 1 Which would you choose?
It doesn't seem unreasonable to use then() to express: "Run this anonymous function whenever the async thing completes. Meanwhile let's do this other stuff right now."
Re: A Modern JavaScript Tutorial
#15The default way promises are used is now async/await. `.then()` should not be introduced as anything more than 'you may find this in older codebases'.
However, when you want a more fine-grained concurrent execution of different asynchronous things, then() still could be very useful.
Re: A Modern JavaScript Tutorial
#16Re: A Modern JavaScript Tutorial
#17The default way promises are used is now async/await. `.then()` should not be introduced as anything more than 'you may find this in older codebases'.
One problem. I’m increasingly coming across devs who’ve never used Promises directly, only async/await. They’re introducing all kinds of problems into code because they don’t have that foundational understanding of Promises. I think it’s essential to know how Promises work, even if we generally recommend async/await.
Also, Promise interface can do things that async/await cannot, such as Promise.all, and other unusual async execution scenarios. It’s important to have those tools in your belt.
Re: A Modern JavaScript Tutorial
#18Excellent. Wish all documentation\tutorial sites were this clean.
Re: A Modern JavaScript Tutorial
#19The default way promises are used is now async/await. `.then()` should not be introduced as anything more than 'you may find this in older codebases'.
No, because you might have to write explicit promises in the browser with async API that are callback based.
You need to understand how promises work to use async/await at first place anyway.
Just like it's better to understand how prototypal inheritance works in JS BEFORE even using a single class declaration.
Re: A Modern JavaScript Tutorial
#20I'm curious. How are my language preferences exposed through HTTP headers?
I think this was a charming way to request volunteers for translation, but I was a bit taken aback.