Commit 16f95c05 authored by Alex Navasardyan's avatar Alex Navasardyan

adding docs about "fail" handler; removing redundant .call in fail()

parent b452c89d
......@@ -116,7 +116,7 @@ Errors also propagate:
```javascript
getJSON("/posts.json").then(function(posts) {
}).fail(function(error) {
}).then(null, function(error) {
// since no rejection handler was passed to the
// first `.then`, the error propagates.
});
......@@ -131,11 +131,22 @@ getJSON("/post/1.json").then(function(post) {
return getJSON(post.commentURL);
}).then(function(comments) {
// proceed with access to posts and comments
}).fail(function(error) {
}).then(null, function(error) {
// handle errors in either of the two requests
});
```
You can also use `fail` for error handling, which is a shortcut for
`then(null, rejection)`, like so:
```javascript
getJSON("/post/1.json").then(function(post) {
return getJSON(post.commentURL);
}).fail(function(error) {
// handle errors
});
```
## Arrays of promises
Sometimes you might want to work with many promises at once. If you
......
......@@ -123,7 +123,7 @@ Promise.prototype = {
},
fail: function(fail) {
return this.then.call(this, null, fail);
return this.then(null, fail);
}
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment