Yesterday was my idol's birthday , Now the whole person is very excited O(∩_∩)O~  Gossip , Let me send an essay as a souvenir ^_^

//////////////////////////////// Text divider //////////////////////////////////////


Just write the code , It's all about variables and functions , Therefore, variable and function naming is very important to enhance code readability .JavaScript The core of language ECMAScript, That is to follow the hump case (Camel case) Nomenclature .Camel case It is used here by the author to refer to “ Small hump case ”( That's lowercase ) Nomenclature ,Pascal case It refers to “ Big hump case ”( The first letter is capitalized ) Nomenclature .

The little hump case nomenclature starts with lowercase letters , Capitalize each subsequent word , such as :var thisIsMyName;

Variables and functions

Variable names should always follow the camel case nomenclature , And the prefix should be a noun .

The function name prefix should be a verb , So you can separate variables from functions .

// Good writing 
var count = 10;
var myName = "Nicholas";
var found = true; // Bad writing : Variables look like functions
var getCount = 10;
var isFound = true; // Good writing
function getName(){
return myName;
} // Bad writing : Functions look like variables
function theName(){
return myName;

Generally speaking , The naming length should be as short as possible , And get to the point . Try to reflect the value data type in the variable name . such as , name count,length and size Indicates that the data type is a number , And name name,title and message Indicates that the data type is a string . But variables named after a single character are like i、j and k Usually used in a loop . Using these can reflect the naming of data types , Make your code easy to read by others and yourself .

Avoid meaningless naming . Such as foo,bar and tmp Such naming should also be avoided , Of course, there are many names in the developer toolbox that you can use as you like , But don't let these names carry other additional meanings . For other developers , If you haven't seen the context , It's impossible to understand the use of these variables .

For function and method naming , The first word should be a verb . Here are some common conventions for using verbs .

dynamic   word contain   The righteous
can Function returns a Boolean value
has Function returns a Boolean value
is Function returns a Boolean value
get Function returns a non Boolean value
set Function to hold a value

Although these function naming rules are not included in the current popular programming style , But in many popular Libraries ,JavaScript Developers will find many of these “ False standards ”.

jQuery Obviously, this function naming convention is not followed , Part of the reason is jQuery How to use methods in , Many methods are used at the same time getter and setter. such as ,$("body").attr("class") You can get it. class The value of the property . For all that , We still recommend using verbs as prefixes to function names .


stay ECMAScript 6 Before ,JavaScript There's no real concept of constants in . However , This does not prevent developers from using variables as constants . To distinguish between ordinary variables and constants , A general naming convention came into being . This Agreement comes from C Language , It's named with capital letters and underscores , Underscores are used to separate words , such as :

var MAX_COUNT = 10;

var URL = "";

It should be noted that , Here are just variables with different naming conventions applied .


stay JavaScript in , Constructors are just preceded by new Function of operator , Used to create objects .

The name of the constructor follows the big hump nomenclature . This distinguishes constructors from variables and ordinary functions . The name of a constructor is often a noun , Because they are used to create instances of a certain type .


author : Xianrui
Source :
The copyright of this article belongs to the author and blog Park , Welcome to reprint , However, this statement must be retained without the consent of the author , And in the article page obvious position gives the original link . Thank You for Your Cooperation .


《 Write maintainable JavaScript》——JavaScript Coding standards ( Two ) More articles about

  1. How to write maintainable object oriented JavaScript Code

    Be able to write maintainable object oriented JavaScript generation Yards don't just save money , And make you popular . Don't believe it ? Maybe you or someone else will come back and reuse your code one day . If you can try to make the experience less painful , You can save a lot of time between . The earth ...

  2. [ turn ]JavaScript Program coding specifications

    original text : author :Douglas Crockford translation : ...

  3. Forward a javascript Code specification of

    google Produce :

  4. To write Shell Scripting best practices , Norm two

    The habits you need to develop are as follows : The code has comments #!/bin/bash # Written by steven # Name: # Version: v1.0 # Parameters : ...

  5. Talking about JavaScript Code specification of programming language

    For those familiar with C/C++ or Java For language Engineers ,JavaScript It's flexible , Simple and easy to understand , The format of the code is also relatively loose . Easy to learn , And apply it to your own code . That's why ,JavaScript The make up ...

  6. 【 forward 】 Netease mailbox front end technology sharing javascript Coding standards

    Netease mailbox front end technology sharing javascript Coding standards Release date :2013-11-26 10:06  source : Netease mailbox front end Technology Center   author : NetEase mail box   Click on :533 Netease mailbox is the earliest one in China ajax Email of Technology . As early as ...

  7. Netease front end JavaScript Coding standards

    After years of development webmail In the process , Netease mailbox front-end team has accumulated a lot of experience , We've developed a lot of foundations js library , Implemented a large number of front-end effects components , Developed mature opoa Framework and api Components , I'd like to share with you . I want to talk with you first today ...

  8. Netease mailbox front end Javascript Coding standards : The specification

    After years of development webmail In the process , Netease mailbox front-end team has accumulated a lot of experience , We've developed a lot of foundations js library , Implemented a large number of front-end effects components , Developed mature opoa Framework and api Components , I'd like to share with you . I want to talk with you first today ...

  9. Java Coding standards

    At the request of the group , Development and testing all need to test Ali coding specification , therefore , It's like a little bit of knowledge about coding specifications , The current project needs to be migrated later , Data migration , Function migration ... All kinds of migration ... Alibaba code specification (Java) In the exam ...

  10. 03-C Language coding specifications and variables

    Catalog : One .C The coding standard of language Two . Variable 3、 ... and . floating-point float Four . Variable name naming rules 5、 ... and . Variable scope and life cycle Back to the top One .C Language programming specifications 1 Statements can be placed in any position 2 Spaces make the code clearer 3 ...

Random recommendation

  1. GPS Latitude and longitude are converted into XY coordinate

    ;        }

  2. JQUERY1.9 Learning notes The basic filter ( Ten ) Non selectors

    Non selectors jQuery( ":not(selector)" ) example : Find out all input The label is not "checked" Of , And highlight its neighbor element span. <!DOC ...

  3. gdbserver Android apk

    gdbserver   Debugging program Bottom call c/c++ Dynamic library , Dynamic library with debugging options Check your phone IP Called by the package c/c++ Ku is in /data/data/ Package name /lib/ Next 1. Jiang An ...

  4. centos install FTP server details ( turn )

    centos install FTP server details classification : linux 2013-12-27 16:45 227 Human reading Comment on (0) Collection report We are here to install vsftpd The server side is an example : 1. Enter into cent ...

  5. Reading notes effective C++ Item 40 Wise and prudent use of multiple inheritance

    1. Two more camps When we talk about multi inheritance (MI) When ,C++ The committee is divided into two basic camps . One camp believes that if inheritance alone is good C++ nature , So much inheritance would be better . Another camp argues that single inheritance is good , But too much inheritance ...

  6. svn On check The next project , use idea open , The menu bar doesn't have svn Tools, solutions

    1. use idea Open your project (idea It's been configured with turtles ) 2. Menu bar click VCS,Enable Version Control Integration... 3. choice Subversion 4. Now , food ...

  7. take labelme Generated .json File visualization code +label.png Contrast processing matlab Code

    labelme_to_dataset Code implementation of instructions : file #!E:\Anaconda3\python.exe import argparse import json import o ...

  8. 【 welfare 】 send Spark Big data platform video learning materials

    No routine is really a gift !! Everybody knows , Big data industry spark Very important , Then I won't say more , My dear uncle found you a job spark Information . Two more words , The basic qualities of a good program ape are learning ability and self drive . The video gives you , Can you ...

  9. Use Ubuntu Of Crontab What you need to pay attention to in timing tasks

    Ubuntu Use crontab Timing task   There are many tutorials online , Now record some of my problems , What to pay attention to : 1. Log storage path of timed tasks On the Internet :cron My log is stored in /var/log/cron Inside ...

  10. Study with me 《HTTP Authoritative guide 》—— Client identification and cookie Mechanism

    Client identification and cookie Mechanism The server needs to distinguish which client . Personal touch HTTP It's anonymous . Stateless requests / Response protocol . Web The site wants : Learn more about the users of the client Tracking the behavior of users browsing the page therefore , There are several kinds of ...