Skip to content

Latest commit

 

History

History
39 lines (25 loc) · 1017 Bytes

func-names.md

File metadata and controls

39 lines (25 loc) · 1017 Bytes

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. For example:

Foo.prototype.bar = 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

Examples of incorrect code for this rule:

/*eslint func-names: "error"*/

Foo.prototype.bar = function() {};

(function() {
    // ...
}())

Examples of correct code for this rule:

/*eslint func-names: "error"*/

Foo.prototype.bar = function bar() {};

(function bar() {
    // ...
}())

Further Reading