JavaScript Naming conventions

Source: Internet
Author: User

Class naming

Example:

var ClassName = function(){ //类名
var _FieldName = "Test Field"; //私有变量
this.PropertyName = "Test Property Name"; //属性

var functionName = function(){  //私有方法
 return "";
}

this.PublicFunctionName = function(pTestName){ //公有方法 pTestName:参数
 var condition = "condition"; //局部变量
 if(condition){    //判断
  return functionName();
 }else{
 }
 var nameCol = ["a","b"]; //数组
 var nameItem = nameCol[0]; //数组项
 for(var i = 0; i < nameCol.length; i++){
 //循环
 }
 var selectName = "item";
 switch(selectName){ //选择
  case "item":
  break;
 }
}
}

Description

. Name all names by Shong

A: Add _ Underscore prefix B: lowercase opening C: Uppercase opening D: Plus lowercase p prefix

Name A B C D
Class name √
Private variable √
Property √
Private method √
Public method
Parameters √
Local variables √

Special Example: array, after adding col;

An array item, followed by an item;

Judgment statement:

if(condition){
 //Code;
}else{
 //Code;
}

Loop statement:

for(var i = 0; i < nameCol.length; i++){
 //Code;
}

SELECT statement:

var selectName = "item";
switch(selectName){
 case "item":
 break;
}

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.