Use of JS semicolon
Http://www.studyofnet.com/news/883.html
Naming conventions
1. Variable Naming conventions:
Use meaningful words and hump-style naming, temporary variables such as: Str,num,arr, loop variable write: i,j,k
2. Global variable naming specification:
Global variables use g as a prefix, such as Glotintime
3. Constant naming conventions:
Use all uppercase, such as: CO
4. Function name naming specification:
A. Unify the use of verbs in the form of nouns, such as: GetVersion ()
B. Words that involve a return value, such as Is,has, which can be used to represent logic, and an inner function preceded by a ' _ ' prefix
C. Optional parameters start with ' opt '
5. Naming the class:
Capitalize first letter
attribute is not a noun with a certain meaning, private attribute plus ' _ '
Method name is a meaningful verb + name, first letter lowercase, private method plus ' _ '
6. Other:
Name in English, without pinyin
Loop variables are defined in the loop
Object
Create an object with literal values
// not good var New Object (); // Good var item = {};
Do not use reserved words as keys
// not good var superman = { class: ' Superhero ', default: {clark: ' Kent '}, Privatetrue}// good var superman = { Klass : ' Superhero ', defaults: {clark: ' Kent '}, hiddentrue};
Array
Create an array with literal amounts
// Good var New Array (); // not good var items = [];
Function
Do not declare a function in a non-function block, you should assign that function to a variable.
// not good if (currentUser) { function Test () { console.log (' Nope. ') ); }} // Good if (currentUser) { varfunction Test () { console.log (' Yup. ') ); };}
Do not name the parameter arguments, which will have an effect on the arguments object within the function
JavaScript Encoding Specification Collection