DEV Community

Discussion on: Easy console.log() inside one liner functions

Collapse
 
jonrandy profile image
Jon Randy 🎖️ • Edited

You could also wrap your function with a logger wrapper function. Ending up with something like:

nums.map(logged(num => <li key={num}>{num}</li>))
Enter fullscreen mode Exit fullscreen mode

The function returned by your logged wrapper function would log inputs, outputs, whatever; as well as calling the passed function and returning its result. This way you could have consistent logging everywhere, and switch it off at a stroke just by modifying the logged function

Collapse
 
js_bits_bill profile image
JS Bits Bill

I like this!

Collapse
 
jonrandy profile image
Jon Randy 🎖️

If you wanted them fully removed though, you would still need to do that. The wrapped versions of the functions will be slower than the originals