I. Preface. The code of conduct for browser-side programming. Typescript also try to follow this rule.
Two. Code style.
2.1 no BOM
UTF-8
coding;
2.2 Add a blank line at the end of the file;
2.2 Use a 4
space as an indent level
2.3 Two unary operators must have a space on each side, and no spaces between the unary operator and the operand object
2.4 The left Curly brace must have a space before it;
2.5 keywords must have a space after;
2.6 When the object is created, :
there must be a space after the attribute, and :
no spaces are allowed before;
2.7 After the function name parameter "(" cannot have the space;
No spaces are allowed in 2.8 () and [];
2.9 No more than 120
one character per line;
When the 3.0 operator wraps, the operator must be at the beginning of the new line;
3.1 A set of statements of different behavior or logic, separated by blank lines, and easier to read;
3.2 put ") {" On one line;
3.3 The mix of arrays and object initialization is written strictly in the style of each object's {and end} in a separate line.
such as: Var array=[
{
DoSomething ...
},
{
//dosomething ...
}
];
3.4 for if...else...
, and try...catch...finally
so on, it is recommended to }
add a newline style after the tail number
if (condition) {
//dosomething ...
}
else {
//dosomething ...
};
3.5 End of function definition does not allow the addition of semicolons
For example: function () {
Dosometing
}
Three. naming
3.1 变量
use Camel命名法
;
常量
全部字母大写,单词间下划线分隔
The naming method used by 3.2;
3.3 类
use Pstringascal命名法
; for example: Catclass;
3.4 枚举变量
Use Pascal命名法
, 枚举的属性
全部字母大写,单词间下划线分隔
The use of the naming method;
3.5 命名空间
Use Camel命名法
;
3.6 类名
Use 名词
;
3.7 函数名
Use动宾短语;
boolean
a variable of type 3.8 is used is
or has
prefaced;
3.9 Promise对象
with 动宾短语的“进行时”
expression;
Four. Notes
4.1 //
followed by a space;
4.2 A blank line must be before the document comment;
4.3 Document Description What, not how;
4.4 {Array<string>} array of type string;
{(Number|boolean)} multi-type;
{? Number} is allowed to be null;
{! Object} is not allowed to be null;
{function (number, Boolean): string}, formal parameter, return value type;
@param {string=} name optional parameter, = type suffix;
@param {... number} args variable length parameter, ... prefix for type;
{*} any type;
@param {*=} name optional any type;
@param {... *} args to grow any type;
4.5 The top of the file must include a file comment, with the @file和@author等
identification file description;
4.6 Using @extends
The inheritance information of the tag class;
4.7//null or undefined
Good
if (Novalue = = null) {
// ......
}
Five.
201505061055_ "JavaScript Coding specification Notes"