Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Cristian-Adrian Frasineanu
5,101 PointsWhy there aren't error-first callbacks?
For me it seems a little bit strange that we pass in the resolver and then the rejector for .then() method. I've worked mostly with APIs which required the error handler first, isn't that a standard? I might be wrong.
Thanks, Cristian
2 Answers
Steven Parker
243,215 Points Even more of a standard (and a bit of a necessity) is that required arguments come before optional arguments. And the failure method in a .then() is optional.
Cristian-Adrian Frasineanu
5,101 PointsYes, correct. I've searched it and it seems that only Node adopted this implementation after all. I believe this is just for prioritizing the error handling inside the callback and not by catching it.
Cristian-Adrian Frasineanu
5,101 PointsCristian-Adrian Frasineanu
5,101 PointsThanks, is it me or only Node.js with the V8 engine use error-first callbacks? I understand that it is a necessity, especially in a loosely typed language like JavaScript to have the optional arguments at the end, but my question now is: if ES5 and ES2015 offer native promises why the callbacks in Node.js are different? Is there an irony or they just wanted to disallow this flexibility when using callbacks?
I haven't searched, but I guess it is impossible to replace the error parameter in Node.js and use a chained .catch() method.
Steven Parker
243,215 PointsSteven Parker
243,215 PointsI wasn't aware of the difference in Node, but I haven't been using it for very long. My JS experience is almost entirely client-side up to now.
I haven't seen it yet myself, but if the previous method call doesn't return the promise, you wouldn't be able to chain.