JavaScript's small accumulation-best practices for anonymous function expressions

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.