Javascript patterns and good parts

Source: Internet
Author: User

To learn a language, it is a shortcut to see a good book on the market. In the past few days, I have taken the time to read two books, JavaScript patterns and JavaScript good parts.

 

# ASI (automatic semicolon insert)

Javascript makes itself very good. If ";" is missing at the end of the code line, he will choose to add one to you. Javascript interpreter is not a god, and often makes mistakes, so we usually don't give him a chance to be awesome.

// Goodif (XX ){//....} // bad. // piaoger used to like this method. It seems that it has to be changed. // try to write C/C ++ and the coding style in the javascritpt era is similar. If (XX ){//....} // good if (color = red | color = blue ){//....} // badif (color = red | color = blue ){//....}

 

 

# Anonymous functions (anonymous function)

Anonymous functions usually appears in functions that do not need to be reused. It can effectively control the scope of variables and construct closure to prevent global variables from being contaminated.

(function(){    // insert code here})();

It is often seen in Javascript libraries such as jquery.

 

# Module Pattern

Http://www.yuiblog.com/blog/2007/06/12/module-pattern/

 

# Try to put <SCRIPT> behind the HTML content

Whether it is a Javascript file or a javascript statement, it is best to put it at the end of the html body;

For performance reasons, script blocks can also be placed at the bottom of the document body

# Delayloading

 

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.