Reputation: 107
it's almost a few months that i'm working with javaScript and i came to understand the meaning of callbacks and now i'm confused : Isn't the concept of promise as the same as callbacks?
API.one(function(err,data){
API.two(function(err,data2){
API.three(function(err,data3){
});
});
});
Upvotes: 0
Views: 28
Reputation: 472
They are similar. For me promises, such as .catch()
, .then()
, do better with handling returns and error handling. So if you have nested callbacks to handle errors, the error may escape one callback function but it WILL be caught by a promise like .catch()
.
this.myFunction(){
$http({method: 'get',
url: url})
.then(function(err,results){
console.log(results);
};
Angular Example
Upvotes: 1