January 2020
Intermediate to advanced
470 pages
11h 13m
English
Doing logging by modifying your functions as we showed isn't difficult, but modifying code is always dangerous and prone to accidents. So, let's put our FP hats on and think of a new way of doing this. We have a function that performs some kind of work and we want to know the arguments it receives and the value it returns.
Here, we can write a higher-order function that will have a single parameter – the original function – and return a new function that will do the following, in sequence:
A possible solution would be as follows:
const addLogging = fn => (...args) => { console.log(`entering ...Read now
Unlock full access