At the time of writing JS, it is often used anonymous function expressions, such as
1 setTimeout (function() {2 console.log (3 }, 1000);
The above function () is the expression of anonymous functions, the advantages of this writing is simple and fast, do not consider the function of the name, very convenient.
However, there are several drawbacks:
1. Anonymous functions do not display meaningful function names in stack traces, making it difficult to debug
2. Anonymous function cannot call itself, only use Arguments.callee reference
3. The anonymous function omits the readability of the code, and a function with a function name can be seen in the name.
So, like the above in-line function expression is very common, but also very powerful useful, the difference between anonymous and named has no effect on this point, to anonymous function named can effectively avoid the above shortcomings, is a best practice.
1 setTimeout (function thisistest () {2 console.log (); 3 });
JavaScript's small accumulation-best practices for anonymous function expressions