To this day, I fail to see the wisdom of writing b => getMoreData(b), when mere getMoreData means exactly the same thing. Because really
getData()
.then(a => getMoreData(a)) // repeat four times
is an equivalent of
const getMoreDataButWrappedWithOneMoreFunction = x => getMoreData(x);
getData()
.then(getMoreDataButWrappedWithOneMoreFunction) // repeat four times
What is the point of getMoreDataButWrappedWithOneMoreFunction, I wonder? Why not just put getMoreData there?
It seems as if the moment a developer learn that in JS he can define a function in the middle of some expression, he immediately forgets he isn't obliged to.
So to give you some context, the code sample in the animation is meant to be easy for beginners to understand and it is not supposed to be too clever. So this was done on purpose in order to show the flow of all the parameters.
However, if you still prefer passing function references instead of function invocations, I have already made another animation illustrating this:
To this day, I fail to see the wisdom of writing
b => getMoreData(b)
, when meregetMoreData
means exactly the same thing. Because reallyis an equivalent of
What is the point of
getMoreDataButWrappedWithOneMoreFunction
, I wonder? Why not just putgetMoreData
there?It seems as if the moment a developer learn that in JS he can define a function in the middle of some expression, he immediately forgets he isn't obliged to.
Hey Maciej, thanks for reaching out.
So to give you some context, the code sample in the animation is meant to be easy for beginners to understand and it is not supposed to be too clever. So this was done on purpose in order to show the flow of all the parameters.
However, if you still prefer passing function references instead of function invocations, I have already made another animation illustrating this:
Cheers.
We still need to wrap the method in an arrow function to keep
this
in the correct context, unfortunately.I really hate this sometimes.