Node. js code specification _ node. js-js tutorial

Source: Internet
Author: User
Tags coding standards
Coding standards are everywhere, but few companies do well in coding standards. I can't help but want to talk about the importance of coding standards. I hope everyone can pay attention to it. When calling a function, there is no space between the function name and the left parenthesis.

There is no space between the function name and the parameter sequence. There is a space between all other syntax elements and the left parenthesis.

Use the small hump naming method as the naming rules for all variables and attributes.

Two spaces are used for indentation and single quotation marks are used.

Join an array. No quotation marks are required unless the key name contains spaces or invalid characters.

Do not merge statements for different purposes into one row.

Do not omit the semicolon at the end of a sentence, even if one row has only one statement.

Do not use the auto-increment (++) and auto-increment (--) operators, instead of the + = and-= operators.

Do not use the "Equal" (=) operator. Only the "strictly equal" (=) operator is used.

All variable declarations are placed in the function header.

All functions are defined before use.

Name constructors and callback functions as much as possible, so that you can see a clearer call stack during debugging.

Try to define all member functions in the constructor through the prototype, define the attributes in the constructor, and then use the new keyword to create an object for the constructor.

Avoid complex inheritance. If you want to inherit, use the inherits function in the util module whenever possible. For example, if A inherits B, it can be util. inherits (A, B ).


References:

Appendix B (BYVoid) of Node. js Development Guide)

Javascript programming style (Ruan Yifeng)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.