4 ms·
My main point was that promises represent an entirely new coding style, which pantomimes the familiar try/catch/return, but isn't quite the same. So you have to
by nolanl 12y ago
My main point was that promises represent an entirely new coding style, which pantomimes the familiar try/catch/return, but isn't quite the same. So you have to learn two systems.
For instance, the following three blocks are not equivalent, but they're easy to mix up:
// executes serially
promise.then(function () {
return somethingThatReturnsAPromise();
}).then(...)
// doesn't wait for something() to return
promise.then(function () {
somethingThatReturnsAPromise();
}).then(...)
// executes something() immediately
promise.then(somethingThatReturnsAPromise()).then(...)
With synchronous code, it's obvious what order things happen in, because you just read top to bottom. But yeah, I do agree that arrow functions make it a bit nicer. :)