_The following examples are based (but no dependent) on Express router._
Considering the following correct case:
router.get('/url', (req, res) => {
...
});
Should you?
Write the callback function as an arrow function as well, if called from an external place?
// controllers.js
export const getUrlController = (req, res) => {
...
});
// routes.js
import { getUrlController } from './controllers'
router.get('/url', urlController);
Or should it rather be a function in this case?
// controllers.js
export const getUrlController = function getUrl(req, res) {
...
};
Arrow functions don't have names, and are really only used best as inline callbacks. I'd recommend using a proper named function in this case.
@ljharb Do you think it is worth clarifying this in the style guide? I think in general the use of functions vs named arrow functions in the global namespace isn't clear from the current airbnb style guide.
// good
function parseSchema(schema) {
...
}
// bad
const parseSchema = (schema) => {
...
};
There is some justification on reasoning at https://stackoverflow.com/a/23045200/325365.
While I agree with that, I don't think that's something that has enough internal consensus at airbnb to warrant inclusion in the guide.
Most helpful comment
Arrow functions don't have names, and are really only used best as inline callbacks. I'd recommend using a proper named function in this case.