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