web development specification - javascript writing specifications

Creative Commons License Copyright: Attribution, allow others to create paper-based, and must distribute paper (based on the original license agreement with the same license Creative Commons )

basic rules

The writing process, the end of each line of code must have a semicolon; all functions are native to develop according to the needs of the XXX project in principle, to avoid code online down down due to contamination of the code (the code || || Shen redundant with existing code violations ... );

Library introduction: For third-party libraries, to be discussed and decided with the rest of the team;

Variable Name: camel named native JavaScript variables claim pure English letters, the first letter should be lowercase, as iTaoLun; jQuery variable claim first character '_', the other with the native JavaScript same rules as:. _ITaoLun; other requirements set of variables statement, to avoid global variables.

Class name: the first letter capitalized, camel named as ITaoLun;.

Function Name: first letter lowercase camel named as iTaoLun ();.

Semantic naming, as far as possible using English words or abbreviations;

Avoid the use of compatibility and resource-consuming methods or properties, such as eval () & innerText;

Late optimization, JavaScript non-comment type Chinese characters must be converted to unicode coding used in order to avoid garbled display when coding errors;

Clear code structure, add comments to improve the function reuse.;

Use === /! == to compare true / false value or prevent some of the JavaScript language casts

Switch must use the default branch

Sometimes it is not the function should return a value, and sometimes does not return a value (it would be best should have a return value: undefined)

for in loop variable var keyword should be scoped to avoid contamination of the scope

Focusing the separated html, reduced reflow, focus on performance.

JavaScript comment, single-line comments using the '// Here is a single line comment', multi-line comments using the / * here more than one line comment * /;

Guess you like

Origin blog.csdn.net/weixin_44198965/article/details/94338252