0

I am new to .js and want to change this arrow function to normal function, for personal interest

module.exports.endpoint = fn =>
(req, res) => {
    Promise.resolve(fn(req, res))
        .catch((err) => {
            this.jsonOutHandler(err, null, res);
        });
};

How to achieve it?

5
  • add function in front, surround the parameter(s) in brackets (here it's just fn ), remove the =>, add { } around the body and a return. Commented Apr 13, 2020 at 10:15
  • = function(fn) { return function(req, res) { etc Commented Apr 13, 2020 at 10:15
  • module.exports.endpoint = function (fn) { return function fun(req, res) { return Promise.resolve(fn(req, res)) .catch(function (err) { return this.jsonOutHandler(err, null, res); }); }}; Commented Apr 13, 2020 at 10:17
  • @MFuatNUROĞLU doesn't return anything. Commented Apr 13, 2020 at 10:17
  • @VLAZ you are right, I've fixed it Commented Apr 13, 2020 at 10:19

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.