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 trialHamzah Iqbal
Full Stack JavaScript Techdegree Student 11,145 PointsHow does the generateHTML work, when no functions are passed to it?
function generateHTML(data) {
const section = document.createElement('section');
peopleList.appendChild(section);
section.innerHTML = `
<img src=${data.thumbnail.source}>
<h2>${data.title}</h2>
<p>${data.description}</p>
<p>${data.extract}</p>
`;
}
btn.addEventListener("click", () => {
getJSON(astrosUrl, (json) =>
{
person.people.map(person=> {
getJSON(wikiUrl + person.name, generateHTML);
});
I can somewhat see the reason for the generateHTML, however I cant see, why no data is passed in as the argument here. How is the data passed in here?
1 Answer
Steven Parker
231,172 PointsIn the "getJSON" call shown here, only a reference to "generateHTML" is being passed as a callback. It's not being called yet.
But if you go look at the definition for "getJSON" (not shown here), you can see that when it does get called (at line 13 of "callback.js"),, it is passed a data argument ("callback(data)
").