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 trialAgata Zurek
Full Stack JavaScript Techdegree Graduate 26,419 PointsHow does generateHTML get its argument passed to it?
Could someone please explain how generateHTML "knows" what its argument is? Thanks!!
1 Answer
Axel Perossa
13,930 PointsYou pass a reference of generateHTML to the getJSON function:
getJSON(wikiUrl + person.name, generateHTML);
In the getJSON function, that reference to generateHTML is stored in the callback parameter (check the function definition of getJSON in the code).
The getJSON function will later call generateHTML in the line
return callback(data);
so that line is the same as doing generateHTML(data). That's the exact moment where you pass the info to generateHTML so it can do its thing.
Agata Zurek
Full Stack JavaScript Techdegree Graduate 26,419 PointsAgata Zurek
Full Stack JavaScript Techdegree Graduate 26,419 PointsThank you! That really helps.