refactor classes, add private, minor fixes
This commit is contained in:
parent
a0c07342ad
commit
1373f6158c
270 changed files with 1513 additions and 890 deletions
|
@ -0,0 +1,20 @@
|
|||
The short answer is: **no, they are not the equal**:
|
||||
|
||||
The difference is that if an error happens in `f1`, then it is handled by `.catch` here:
|
||||
|
||||
```js run
|
||||
promise
|
||||
.then(f1)
|
||||
.catch(f2);
|
||||
```
|
||||
|
||||
...But not here:
|
||||
|
||||
```js run
|
||||
promise
|
||||
.then(f1, f2);
|
||||
```
|
||||
|
||||
That's because an error is passed down the chain, and in the second code piece there's no chain below `f1`.
|
||||
|
||||
In other words, `.then` passes results/errors to the next `.then/catch`. So in the first example, there's a `catch` below, and in the second one -- there isn't, so the error is unhandled.
|
13
1-js/11-async/03-promise-chaining/01-then-vs-catch/task.md
Normal file
13
1-js/11-async/03-promise-chaining/01-then-vs-catch/task.md
Normal file
|
@ -0,0 +1,13 @@
|
|||
# Promise: then versus catch
|
||||
|
||||
Are these code fragments equal? In other words, do they behave the same way in any circumstances, for any handler functions?
|
||||
|
||||
```js
|
||||
promise.then(f1).catch(f2);
|
||||
```
|
||||
|
||||
Versus:
|
||||
|
||||
```js
|
||||
promise.then(f1, f2);
|
||||
```
|
Loading…
Add table
Add a link
Reference in a new issue