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 trialGeorge Akinian
17,615 Pointshow 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
2 Answers
Azriel Garcia
6,881 PointsHey
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 Moran
14,052 PointsThe "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!