Dojo JavaScript Programming specification

Source: Internet
Author: User

Objective

Quite a good JavaScript programming style specification, it is recommended that you use this specification to write JavaScript. Original link: http://dojotoolkit.org/developer/StyleGuide.

Translation (translated by): I.feelinglucky{at}gmail.com from http://www.gracecode.com, reproduced please indicate the source, author and translator, thank you for your cooperation.

This article address: Http://code.google.com/p/grace/wiki/DojoStyle.

Order

Any violation to this guide is allowed if it enhances readability.

All the code has to be made easy for others to read.

Quick Read Reference

Core API Please use the following style:

structure rules note
module lowercase do not use multiple semantics (Never multiple words)
class Camel  
public method mixed Other external calls can also be used lower_case (), such a style
public variable mixed  
constant Camel or uppercase /td>

The following are not necessary, but are recommended for use:

Structure Rules
Private method Mix, Example: _mixedcase
Private variable Mix, Example: _mixedcase
Method parameter Mix, Example: _mixedcase, Mixedcase
Native (local) variables Mix, Example: _mixedcase, Mixedcase

Naming conventions

The variable name must be a lowercase letter.

The name of the class uses the camel naming rules, for example:

Account, EventHandler

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:

var NodeTypes = {
Element : 1,
DOCUMENT: 2
}

Abbreviated words cannot use uppercase names as variable names:

Getinnerhtml (), getXml (), XmlDocument

The command of a method must be a verb or a verb phrase:

Obj.getsomevalue ()

The naming of public classes must be named with a mixed name (mixedcase).

The name of a CSS variable must use its corresponding common class variable.

Variable attribute members of a private class must be named with a mixed name (Mixedcase), preceded by an underscore (_). For example:

var MyClass = function(){
var _buffer;
this.doSomething = function(){
};
}

If you set the variable to private, you must precede it with an underscore.

this._someprivatevariable = statement;

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

Settopic (topic)//Variable topic as topic type of variable

All variable names must be in English name.

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.

If the variable has its implied return value, avoid using a similar method:

GetHandler (); Avoid using Geteventhandler ()

Public variables must clearly express their own attributes to avoid ambiguity, for example:

MouseEventHandler, not 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//rather than Dojo.events.mouse.MouseEventHandler

A class/constructor can be named with the name of an extension of its base class, so that the name of its base class can be found correctly and quickly:

EventHandler

Uieventhandler

MouseEventHandler

A base class can reduce its name by explicitly describing its properties:

MouseEventHandler as opposed to Mouseuieventhandler.

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.