#regular function equivalent of arrow function

5 messages · Page 1 of 1 (latest)

viral notch
#

Hey everyone, I have this higher order function in arrow format ```js

const catchErrors = (fn) => (req, res, next) => {
Promise.resolve(fn(req, res, next)).catch(next);
};I'm trying to come up with the equivalent of it using regular function statementsjs
function catchErrors(fn) {
return function inner(req, res, next) {
Promise.resolve(fn(req, res, next).catch(next));
};
}

#

Are these two equivalent?

#

If they are, they are having different outcomes when I use them in my project. I know arrow functions impact the 'this' keyword but where I am using it, there is no 'this' keyword

coarse nexus
# viral notch Are these two equivalent?

They're not equivalent. The first has the Promise.resolve only wrapping the fn() call with .catch() outside of it. The second it's around everything including the .catch().

viral notch
#

@coarse nexus thank you very much for catching that xD