When using a function with a callback parameter, I found that this method works perfectly fine:
DB.last(user,(data) => res.json(data));
However, when attempting to refactor it for better readability as shown below:
DB.last(user,res.json);
The structure of DB.last is as follows:
static last(user, callback) {
let data = {name: user, registered: new Date()};
callback(data);
}
This specific function call of DB.last is within an express router script.
While there seems to be a clear distinction between the two approaches, it makes sense to me to pass res.json as a callback parameter to my DB module (considering functions can be passed in JavaScript), but unfortunately, this approach doesn't work as expected.
What could be causing this issue and why isn't it functioning properly?