Require Function Expressions to have a Name (func-names)

A pattern that’s becoming more common is to give function expressions names to aid in debugging, such as: = function bar() {};

Adding the second bar in the above example is optional. If you leave off the function name then when the function throws an exception you are likely to get something similar to anonymous function in the stack trace. If you provide the optional name for a function expression then you will get the name of the function expression in the stack trace.

Rule Details

The following patterns are considered problems:

/* eslint func-names: 2*/ = function() {}; /*error Missing function expression name.*/

(function() {                      /*error Missing function expression name.*/
    // ...

The following patterns are not considered problems:

/* eslint func-names: 2*/ = function bar() {};

(function bar() {
    // ...

Further Reading


This rule was introduced in ESLint 0.4.0.