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 trialChristopher Johnson
12,829 PointsFew syntax questions
Few short questions:
1. Why is there no '()' required at the end of 'printError'?
2. Can you explain, specifically the {message:x}, the format of:
'printError({message: 'xyz' + '(' + response.x + ')'});'
3. I'm a little confused with 'module.exports.get = get;'
Thanks for the answers, in advance!
1 Answer
Steven Parker
231,269 PointsI'll try to answer your questions:
- Why is there no '()' required at the end of 'printError'?
When you establish an event handler, you pass it a function, either as an anonymous function defined on the spot, or as the name of a function. You do not want to invoke the function, which would happen if you added the parentheses after the name. It will be invoked later, when the event occurs.
- Can you explain, specifically the {message:x}, the format of:
'printError({message: 'xyz' + '(' + response.x + ')'});'
The printError function expects to be given an object that has a property named error. The brackets here create a temporary anonymous object, and the term message: inside it indicates that it has a property of that name. Following the colon is the content of that property, which is a string built up by concatenating literal strings along with the value represented by response.x.
- I'm a little confused with 'module.exports.get = get;'
This just sets the get function (once again, named but not invoked) as a property of module.exports, according to the node convention for making functions exportable.