JavaScript code specification

Summary: All JavaScript projects apply the same specification##JavaScript code specification Code specification usually includes the following aspects: The naming rules of variables and functions Spaces, indentation, the use rules of comments and other common specifications... The code of the specification can be easier to The code specification for reading and maintenance is generally stipulated before development, and the same specification can be applied to

all .

Design principles:

1. Atomic idea: that is, each function does one thing;

2. Inductive idea: the same class 3. Easy to

maintain: it is convenient for later people to carry out quick maintenance;

4. Easy to expand: that is, different changes can be made according to each different project;

5. Common front-end design mode: some front-ends can be used universally 6. Pay attention to write comments well, and

write comments to specific points;

JavaScript code specifications

Code specifications usually include the following aspects:

naming rules for variables and functions

Space , indentation, rules for the use of comments

Other common specifications...

Specifications The code can be easier to read and maintain. The

code specification is generally stipulated before development, and can be set in consultation with your team members. Variable

names It is recommended to use camelCase for variable names: firstName = "John"; lastName = "Doe" ; Click and drag to move Prefix specification: Each local variable needs to have a type prefix, which can be divided into:









s: Represents a string. For example: sName, sHtml;

n: indicates a number. For example: nPage, nTotal;

b: represents logic. For example: bChecked, bHasLogin;

a: Represents an array. For example: aList, aGroup;

r: means regular expression. For example: rDomain, rEmail;

f: means function. For example: fGetHtml, fInit;

o: Indicates other objects not involved in the above, such as: oButton, oDate;

g: Indicates global variables, such as: gUserName, gLoginTime

Space and operator

Usually required before and after the operator ( = + - * / ) Add spaces:

var x = y + z; var values ​​= ["Volvo", "Saab", "Fiat"];
Click and drag to move
Code indentation and line wrapping Indentation Use the same

indentation

on the same system Standard, this article advocates an indent size of 4 spaces. Each compiler defines the size of the blank space replaced by the Tab key differently. It is recommended to reset the Tab shortcut in the editor to 4 spaces when setting up the development environment. Most compilers provide this feature. Otherwise, it is recommended to indent by 4 spaces.

Line breaks must be broken

at the following positions:

after each independent statement;

​​​​​​​Original

link http://click.aliyun.com/m/23859/

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326634768&siteId=291194637