Nodejs does not have an official document that specifies the code style of the application, but has some de facto conventions.
Indent- Two spaces
Line width-80 characters
Statement delimiter
It is recommended to use semicolons, even if there is only one statement on a line, do not omit semicolons
Variable definition-- always use var to define variables and ensure that each statement defines a variable
Variable name and attribute name--Small hump-type naming method
Function--General function small hump type; construction function Big Hump
Quotation marks--unity as single quotation mark
Initialization of associative arrays
var = {Put in a row, below a pair of key values for each line, keep two spaces indented, end with a semicolon,}; Finally a separate line;
For each pair of key values, the quotation marks are not used unless there are spaces or illegal characters in the key value name.
Equal sign--= = =
Named functions
The constructor and callback function are named as much as possible, and the call stack can be clearly displayed when debugging.
A callback function that contracts the first argument is the Error object err.
Object definition-Try to define all member functions through the prototype, define the attributes within the constructor, and then create the object with the new keyword on the constructor; never define the property as a prototype.
Inheritance-Use the Inherits function in the Util module as much as possible.
This article is from "Whispering Autumn Wind" blog, please be sure to keep this source http://xjhznick.blog.51cto.com/3608584/1535712