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 trialWendy Cortes
Full Stack JavaScript Techdegree Graduate 16,375 PointsFor the example of mathPromise, why .then(addFive) and not .then(addfive(value))
for this part:
const value = 5; mathPromise .then(addFive) .then(double) .then(finalValue) .catch( err => console.log(err) )
How are we calling the functions inside the methods without including the parameter value?
1 Answer
Steven Parker
231,268 PointsJust naming the function doesn't call it, it passes it to the handler which will call it later when the "then" condition is satisfied. At that time, it will be passed the value which the "then" is waiting for.
It wouldn't make sense to call it right now since the value needed to pass to it isn't available yet.
JASON LEE
17,352 PointsJASON LEE
17,352 PointsThis has been the hardest part for me when understanding promises. The callback function, parameter, argument, etc.
For instance, just looking at this part
mathPromise.then(addFive)
The return or resolved (value) from
mathPromise
is implied as passed as an argument. At least that's the way I think of it.mathPromise.then(addFive)
===mathPromise.then(value => addFive(value))
In the left side of the equation, even though
value
isn't explicitly written out, it's implied.Someone please feel free to correct me if I'm mistaken.