Node.js coding specification
- 2020-03-30 03:31:49
- OfStack
When a function is called, there is no space between the function name and the left parenthesis.
There is no space between the function name and the parameter sequence. All other syntax elements have a space between them and the open parenthesis.
Use the small hump nomenclature as the naming convention for all variables and attributes.
Use two Spaces for indentation and use single quotes.
Associative arrays do not use quotes unless there is a space or an illegal character in the key name.
Do not combine statements for different purposes into a single line.
Do not omit semicolons at the end of a sentence, even if there is only one statement in a line.
Do not use the self - increment (++) and self - decrement (--) operators. Use += and -= instead.
Do not use the equality (==) operator, only the strict equality (===) operator.
All variable declarations are placed at the head of the function.
All functions are defined before they are used.
Try to name constructors and callbacks so that you can see the call stack more clearly when debugging.
Try to prototype all the member functions, define the properties in the constructor, and then create the object using the new keyword on the constructor.
Avoid complex inheritance, and if you do, try to use the util module's its function. For example, if A inherits B, you can use util. Inherits (A,B).
Reference:
Appendix B (BYVoid) of the node. js development guide
Javascript programming style (ruan yifeng)