Nodejs becomes a norm--advice

Source: Internet
Author: User

Nodejs does not have an official document that specifies the code style of the application, but has some de facto conventions.

  1. Indent- Two spaces

  2. Line width-80 characters

  3. Statement delimiter

    It is recommended to use semicolons, even if there is only one statement on a line, do not omit semicolons

  4. Variable definition-- always use var to define variables and ensure that each statement defines a variable

  5. Variable name and attribute name--Small hump-type naming method

  6. Function--General function small hump type; construction function Big Hump

  7. Quotation marks--unity as single quotation mark

  8. 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.

  9. Equal sign--= = =

  10. 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.

  11. 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.

  12. 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

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.