Introduction to JavaScript Programming Specification (1/3)

Source: Internet
Author: User
Tags mixed naming convention

Naming conventions 1. Variable names must be lowercase letters.
2. The naming of classes uses camels to name the rules, for example:

Account, EventHandler
3. Constants must be declared in the object (class) or in the front of the enumeration variable. Enumeration variables must be named in real sense, and their members must use camels to name the rules or use uppercase:

The code is as follows Copy Code
var nodetypes = {
Element:1,
Document:2
}

4. Abbreviated words cannot use uppercase names as variable names:

The code is as follows Copy Code
Getinnerhtml (), getXml (), XmlDocument

5. The order of the method must be a verb or a verb phrase:

The code is as follows Copy Code
Obj.getsomevalue ()

6. The naming of public classes must be named with a mixed name (mixedcase).
The name of a 7.CSS variable must use its corresponding common class variable.
8. Variable attribute members of a private class must be named with a mixed name (Mixedcase), preceded by an underscore (_). For example:

The code is as follows Copy Code
var MyClass = function () {
var _buffer;
this.dosomething = function () {
};
}

9. If the variable is set to private, the underscore must precede it.

The code is as follows Copy Code
this._someprivatevariable = statement

;
10. A generic variable must use a type name that is consistent with its name:

Settopic (topic)//Variable topic as topic type of variable
11. All variable names must be in English name.
12. If a variable has a broader scope (large scope), it must use a global variable, which can then be designed as a member of a class. Relatively small scopes or private variables are used to name simple words.
13. If the variable has its implied return value, avoid using a similar method:

GetHandler (); Avoid using Geteventhandler ()
14. Public variables must clearly express their own attributes and avoid ambiguous meanings, such as:

MouseEventHandler
, rather than MSEEVTHDLR.
Please pay attention to this rule again, the advantage of doing so is very obvious. It can express the meaning defined by the expression explicitly. For example:
   

Dojo.events.mouse.Handler//instead of Dojo.events.mouse.MouseEventHandler
15. Class/constructor can be named with the name that extends its base class, so that you can correct, Quickly find the name of its base class: The
EventHandler
Uieventhandler
MouseEventHandler
Base class can reduce its name by explicitly describing its properties:
Mouseeventh Andler as opposed to Mouseuieventhandler.

The special naming convention term "Get/set" does not connect to a field unless it is defined as a private variable.
The variable name preceded by "is" should be a Boolean value, and the same can be "has", "can" or "should".
The term "compute" as a variable name should be a variable that has already been evaluated.
The term "find" as a variable name should be a variable that has been found complete.
The term "initialize" or "init" as the variable name should be a class or other type of variable that has already been instantiated (initialized).
UI (user interface) control variables should be added to the control type after the name, for example: Leftcombobox, Topscrollpane.
The plural must have its public name convention (original: Plural form must be used to name collections).
The variable name convention with "Num" or "count" is a number (object).
The duplicate variable suggests a variable with the name "I", "J", "K" (and so on).
Supplementary terms must be used, for example: Get/set, Add/remove, Create/destroy, Start/stop, Insert/delete, begin/end, etc.
You can abbreviate the name as much as possible using abbreviations.
A Boolean variable name that avoids ambiguity, for example:
Isnoterror, Isnotfound is illegal.
The error class suggests adding "Exception" or "error" after the variable name.
method if you return a class, you should indicate what is returned on the name, or if it is a procedure, what you have done.
File indentation use a tab stop with 4 blank characters.
If your editor supports file tags, please add the following line to make our code easier to read:

Vim:ts=4:noet:tw=0:
Foreigners use VIM Editor more, this article can choose to follow.

home 1 2 3 last
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.