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 trialJohnny Garces
Courses Plus Student 8,551 Pointswhy does the second parameter of bindTaskEvent NOT include parenthesis?
I see that the function bindTaskEvent takes in 2 parameters: the taskListItem and checkBoxEventHandler,
I see in the video that the function is called like this: bindTaskEvent(incompleteTasksHolder.children[i], taskCompleted).
shouldn't the second parameter include the parenthesis to show that it's a function? shouldn't the function be called like this: bindTaskEvent(incompleteTasksHolder.children[i], taskCompleted() ) ?
2 Answers
0yzh
17,276 PointsHey Johnny,
In this case, you are only passing the function 'taskCompleted' through as a parameter. If you use parenthesis there you would be invoking or calling the function, so the code would not work properly. You don't need to show that it is a function since the JavaScript engine already knows that 'taskCompleted' is a function in its memory space(because you have already created it earlier in your code).
Donald Brunais
8,895 PointsYou are passing the function not invoking the function. So you are given bindTaskEvent a function and bindTaskEvent will call it in the function. If you use the parenthesis it would evaluate it and send the return value of taskCompleted to bindTaskEvent.
Johnny Garces
Courses Plus Student 8,551 Pointsthanks for your post, Donald!
Johnny Garces
Courses Plus Student 8,551 PointsJohnny Garces
Courses Plus Student 8,551 Pointswow- this is cool. this is what functional programming is all about. thanks for this answer, Huy!