JavaScript Encoding Specification Collection

Source: Internet
Author: User

Use of JS semicolon

Http://www.studyofnet.com/news/883.html

Naming conventions

1. Variable Naming conventions:
Use meaningful words and hump-style naming, temporary variables such as: Str,num,arr, loop variable write: i,j,k

2. Global variable naming specification:
Global variables use g as a prefix, such as Glotintime

3. Constant naming conventions:
Use all uppercase, such as: CO

4. Function name naming specification:
A. Unify the use of verbs in the form of nouns, such as: GetVersion ()
B. Words that involve a return value, such as Is,has, which can be used to represent logic, and an inner function preceded by a ' _ ' prefix
C. Optional parameters start with ' opt '

5. Naming the class:
Capitalize first letter
attribute is not a noun with a certain meaning, private attribute plus ' _ '
Method name is a meaningful verb + name, first letter lowercase, private method plus ' _ '

6. Other:

Name in English, without pinyin
Loop variables are defined in the loop



Object

Create an object with literal values

// not good var New Object (); // Good var item = {};

Do not use reserved words as keys

// not good var superman = {    class: ' Superhero ',    default: {clark: ' Kent '},     Privatetrue}// good var superman = {    Klass : ' Superhero ',    defaults: {clark: ' Kent '},    hiddentrue};

Array

Create an array with literal amounts

// Good var New Array (); // not good var items = [];

Function

Do not declare a function in a non-function block, you should assign that function to a variable.

// not good if (currentUser) {    function  Test () {        console.log (' Nope. ') );    }} // Good if (currentUser) {    varfunction  Test () {        console.log (' Yup. ') );    };}

Do not name the parameter arguments, which will have an effect on the arguments object within the function

JavaScript Encoding Specification Collection

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.