Different callbacks for error or error as first argument?
Posted
by
Florian Margaine
on Programmers
See other posts from Programmers
or by Florian Margaine
Published on 2012-04-12T10:35:22Z
Indexed on
2012/04/12
11:41 UTC
Read the original article
Hit count: 484
JavaScript
|error-handling
We (and the JS SO chat room) had a talk with @rlemon some days ago about his Little-XHR library about error handling.
Basically, we wanted to decide which error handling pattern should be used:
xhr.get({
// Some parameters, and then
success: function(data) {},
failure: function(data) {}
})
Or:
xhr.get({
// Some parameters, and then
callback: function(err, data) {}
})
One is more jQuery-like, while the other is more Node-like. Some say that the first pattern makes you think more about handling error. I think the opposite, since you may forget the other callback function, while the argument is always there on the second pattern.
Any opinion/advantage/drawback about both these patterns?
© Programmers or respective owner