Pattern: Anonymous function expression
Issue: -
Anonymous functions show up as '' in stack traces, making it difficult to debug errors. Named function expressions provide better stack traces by including the function name, making it easier to identify where an error occurred.
Example of incorrect code:
Foo.prototype.bar = function() {};
const handler = function() {
throw new Error('Something went wrong');
};
Example of correct code:
Foo.prototype.bar = function bar() {};
const handler = function errorHandler() {
throw new Error('Something went wrong');
};