Asking "should" you use one technique or another is mostly off-limits in SO.
I'm going to answer a related question, though, of when you can and cannot use the technique and what (dis-)advantages there may be.
You can always write foo (x => bar (x))
. You can't always write foo (bar)
. An example of why can be found in another Q & A. A common example of this from my experience is a recursive function with a second parameter which is defaulted in the initial call and passed on subsequent ones. Such a function cannot be successfully passed by simple reference to map
, because map
supplies additional parameters besides the expected value.
But that's the unusual case. If your function has no default parameters, there seem little use in the wrapper. One argument is simply that if you're going to replace foo (bar)
with foo (x => bar (x))
, why shouldn't you take it one step further and use foo (y => (x => bar (x)) (y))
or foo (z => (y => (x => bar (x)) (y)) (z))
.
The wrappers work, but add nothing... except, as you point out as a place to hang a breakpoint.
This could be a legitimate case for you. I don't spend much time in debuggers these days, but when I do, I might occasionally temporarily add such a wrapper. But I remove them afterward. I find that clean code is of high importance, and unnecessary wrappers simply clutter things up. In code reviews, I run constantly against this pattern:
const foo = (...args) => {
// do something with args
return new Promise ((resolve, reject) => {
bar (something).then(
(a) => {
resolve (a);
}, (err) => {
reject (err);
}
);
});
}
Which I always need to point out can be much more cleanly written as:
const foo = (...args) => {
// do something with args
return new Promise ((resolve, reject) => {
bar (something) .then (resolve, reject);
});
}
Then I have to point out further that even this can be better written as
const foo = (...args) => {
// do something with args
return bar (something);
}
The point is that the function wrappers around resolve
and reject
are just clutter. So is the Promise wrapper around bar
. It doesn't hurt the outcome, has only a minor impact on performance, but it offers little to balance out the clutter.
(And look, I tried to avoid opinion here, but really couldn't.)