1.js programming style. ---to write maintainable javascript

Source: Internet
Author: User

1. Use 4 space characters as an indent level.

2. Do not omit semicolons. ---> Automatic insertion of the semicolon mechanism is complex and difficult to remember.

3. The length of a line is limited to 80 characters.

4. Typically, after the operator wraps, the next line increments by two levels of indentation.

5. When assigning a value to a variable, the position of the second row should remain aligned with the position of the assignment operator.

6. Empty lines add a blank line between the local variable and the first statement between the methods before the logical fragment is inserted between the two lines to improve readability.

7. Naming rules, using camel-type lowercase, which starts with lowercase letters, each subsequent word is capitalized.

8. Constants use uppercase letters and underscores.

9. The constructor is named using the Big hump method.

10. Strings can use single quotes or double quotes, which is best used in a style from beginning to end. Using the \ Number to create a multiline string is an illegal JavaScript syntax but it is true that you can create multiple lines of string in your code. Use the + sign to replace \

var longstring = ""

Correct usage:

var longstring = "Here's the story, of a man" +                           "named Brady.";

One. Null

Scenarios that use NULL:

1) used to initialize a variable, the variable may be assigned to an object.

2) For comparison with an already initialized object, this variable can or may not be an object.

3) used as a parameter when the function's parameters are expected to be an object.

4) When the return value of a function is expected to be a pair of images, it is used as the return value.

scenarios where null should not be used:

1) do not use NULL to detect if a parameter is passed in.

2) do not use NULL to detect a variable that is initialized.

Null should be considered a placeholder for the object.

nudefined.

  

var Person ; typeof // ' undefined ' typeof // "undefined"

13. Object Direct volume creation objects can directly and efficiently complete the task of creating objects.

14. Create an array using the array direct amount. Do not approve the display array constructor to create arrays.

1.js programming style. ---to write maintainable javascript

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.