Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.
how come console.dir being a method is not taking any arguments here?
If it is suppose to print the body why is body not inside the parentheses ? how is body getting passed into the console.dir method.? isn't it suppose to be something like console.dir(document.body); ? I am just trying figure out how it is being wired here? Perhaps console.dir already knows it is taking in the body of the studentProfile because of the wiring studentprofile.on("end", console.dir) and therefore it is redundant to pass an argument inside console.dir method?. I just like to know what wires the wiring, I guess? Thanks
It's because in this instance they're defining console.dir as the call back so when the event fires it calls the method console.dir with the parameter passed in
Hope that helps if not I can provide a more detailed example
Brendan Moran14,052 Points
The "end" event passes the full body to the callback, in this case "console.dir."
It is the same as if we did something like this:
request.on("end", body => console.dir(body))
However, this would be redundant because the end event automatically passes the body as an argument, and console.dir will accept that argument because it is a method that is programmed to receive an object of some sort and display it in the console.
I hope that helps!