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 trialdamon5
11,405 Pointsxhr.onerror = () => reject(Error('A network error occurred') ); Why is this written this as a function?
In this video I understand why we are doing this but not why its written like this. I spend more time looking up the unexplained things casually dropped in the videos than I do learning what the video is about.
2 Answers
Steven Parker
231,172 PointsThe purpose of the "onerror" attribute is to hold a reference to a function that will be called when an error occurs.
This code is assigning it with an anonymous function expression.
damon5
11,405 PointsOhh. Haha ok. I actually figured it out shortly after but thanks again for your answer. You seem to know your stuff Steven. I was wondering as a matter of opinion, me brain feels like its folded in half before I 'get' it with a few of these concepts. Worried I may not be bright enough to do this half the time. Is this normal or is it if I am struggling now I may be in trouble?
Steven Parker
231,172 PointsThat all sounds normal to me, particularly if you're learning coding for the first time.
Happy coding!