JS Code Password Specification series

Source: Internet
Author: User
Tags naming convention

See a joke on Weibo

"I will be the CEO to marry mating to embark on the pinnacle of life, must hire two long legged Big Bear's sister." A help me to think of the variable name, a help me want git commit message! ”

It can be seen that the problem of naming is troubling people like me. hahaha

function naming, variable naming, etc. is a frequent problem that bothers me.

Function naming: uniform use of verbs or verbs + noun forms----fninit ()

If there is an intrinsic function then "_" begins with _fninit ().

Object method naming using Fn+ object class name + verb + noun form fnanimatedorun ()

An event response function is named fn+ trigger event object name + Event name or module name fndivclick ()

a list of commonly used verbs is attached:

Get get/set settings, add add/remove Delete
Create creates/destory remove start start/stop stop
Open on/close off, read read/write write
Load load/save Save, create creates/destroy destroy
Begin/end End, backup/restore restore
Import imports/export export, split split/merge merge
Inject injected/extract extract, attach adhesion/detach detachment
Bind bind/separate Detach, view view/browse Browse
Edit/modify Modify, select Select/mark tag
Copy copy/paste paste, undo undo/redo Redo
Insert insertion/delete Remove, add adds/append
Clean cleanup/clear cleanup, index index/sort sort
Find Find/search Search, increase increase/decrease decrease
Play play/pause pause, launch start/run run
Compile compile/execute execution, debug debug/trace Trace
Observe watch/listen Monitor, build build/publish Release
Input/output output, encode encoded/decode decoding
Encrypt encryption/decrypt decryption, compress compression/decompress decompression
Pack Pack/unpack unpacking, parse parsing/emit generation
Connect connection/disconnect Disconnect, send sends/receive receive
Download Download/upload upload, refresh/synchronize sync
Update/revert Restore, lock lock/unlock unlock
Check out checkout/check in check-in, submit submission/commit delivery
Push push/pull Pull, expand expand/collapse Fold
Begin Start/end end, start/finish complete
Enter/exit exit, abort/quit leave
Obsolete waste/depreciate waste, collect collect/aggregate gather

  

Variable name:

Some of the default specifications do not say (constant capital, circular variable shorthand, camel type, etc.)

There is no specification for a variable name, and one of the other's specifications is for reference only.

Plan by Type:

S: Represents a String. For example: sname,shtml;
N: Represents a number. For example: npage,ntotal;
B: Representation logic. For example: Bchecked,bhaslogin;
A: Represents an array. For example: Alist,agroup;
R: Represents the regular expression. For example: Rdomain,remail;
F: Represents a function. For example: Fgethtml,finit;
O: Other objects that are not mentioned above, for example: obutton,odate;
G: Represents a global variable, for example: Gusername,glogintime;

  

Differentiate by prefix:

$: Represents a jquery object. For example: $Content, $Module;
A more extensive naming convention for jquery object variables.
J: Represents a jquery object. For example: Jcontent, Jmodule;
Another way to name a jquery object variable.
fn: Represents a function. For example: Fngetname,fnsetage;
The prefix with the above function is slightly different, instead of using FN, the individual thinks that FN can better distinguish between ordinary variables and function variables.
Dom: Represents a DOM object, for example: Domform,dominput;
Native DOM methods and properties are used in many areas of the project, and can be adapted to the needs of the team.

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.