This time I will explain to you about camel case naming and how to use camel case naming in JS, as well as precautions before use. Let’s look at the detailed introduction below.
Notes before using camel case naming: 1. Due to the characteristics of Javaobject-orientedprogramming, when naming, you should try to choose nouns
when naming variables or functions. When one or more single words are connected together to form a unique identifying word, the first letter starts with lowercase and the first letter of each word is capitalized (except for the first word).
For example: myFirstName
Writing specifications for a package name (Package) It is recommended to use the top-level domain name of the company or organization as the prefix of the package name. The purpose is to ensure that the package used within each company/institution The uniqueness of the name. Package names are all lowercase letters and have practical distinguishing significance.
1.1 General requirements 1. Choose a meaningful name that can quickly convey the purpose of the class.
2. All package names must use lowercase English letters.
1.2 Practical application Layering is often used in application systems, including Dao layer (database access), Service layer (business processing), and Web layer (page control action class).
1. The first few names of the package name are fixed names. If it is a website, the domain name of the website is written in reverse. If the domain name has not been determined, the names fixed by the company are used. For example: net.vschool
2. The next word in the package name is the name of the module. For example: user module, the package name is net.vschool.user
3. Regarding the access operation of the module, it adopts a hierarchical form and is generally divided into:
Dao layer operation: generally defined in net .vschool.xxx.dao, where xxx is the module name.
Service layer operation: generally defined in net.vschool.xxx.servie.
Web layer operation: generally defined in net.vschool.xxx.action.
The following are examples of user modules:
net.vschool.user net.vschool.user.dao net.vschool.user.action net.vschool.user.service
Writing specifications for second-class names (Class) Class names must use nouns. If a class name contains multiple words, then each word comes first The first letter is capitalized, and the subsequent letters are lowercase. The undulations are like a hump, and the person is named in the hump style. When naming a class, it must be accurate, concise, and easy to understand. Try to use complete words and avoid using abbreviations (except those that are generally recognized)
2.1 Naming of classes 2.1.1 General requirements 1. Choose a meaningful name that can quickly convey the purpose of the class.
2. Referring to the java camel case naming method, the first letter of the class name must be in uppercase. If the class name is a combination of multiple words, then the first letter of each word must be in uppercase. For example: StudentAnswer.java
3. When you want to distinguish between interface classes and implementation classes, you can add "Impl" after the class.
For example: Interface class: UserInterface.java Interface implementation class: UserInterfaceImp
4. It is recommended that entity classes have no suffix names.
2.1.2 Layering is often used in actual application application systems, Dao layer (database access), Service layer (business processing), Web layer (page control action class), the name of the class in each layer should be as Bring this layer suffix.
1. Dao layer
a. Interface class: defined in the form of JavaBean+Interface+Dao, that is, entity object+Interface+Dao.
For example: UserObject interfaceClass: UserInterfaceDao, where xxx is the module name.
b. Implementation class: defined in the form of JavaBean+Interface+Impl+Dao, that is, entity object
+Interface+Impl+Dao. For example: User object implementation class: UserInterfaceImplDao
2, Service layer
a, Interface class: defined in the form of Xxx+Interface+Service, that is, module+Interface+Service.
For example: User ManagementInterface class: UserMsgInterfaceServiec
b. Implementation class: defined in the form of Xxx+Interface+Impl+Service, that is, module+Interface+
Impl+Service. For example: User management implementation class: UserMsgInterfaceImplServiec
3. Web layer (action class)
a. Implementation class: defined in the form of Xxx+Operator+Action, that is, module + operation +Action. For example,
User module User+Delete operation Delete+Action = UserDeleteAction
2.1 Naming of variables 2.2.1 Ordinary variables 2.2.2.1 General requirements 1. Choose a meaningful name that can quickly convey the The purpose of the variable.
2. Refer to the java camel case naming method, the first letter starts with lowercase, and the first letter of each word is capitalized (except the first word).
2.2.2.2 Practical application 1. The basic structure of variable naming is typeVariableName, and a 3-character prefix is used to represent the data type.
For example, define an integer variable: intDocCount, where int indicates the data type, followed by the ideographic English name, with the first letter of each word capitalized.
2. Variable usage skills:
a. Do not use the same variable in a function to represent two values with different meanings.
b、除非是在循环中,否则一般不推荐使用单个字母作为变量名,i、j、k等只作为小型循环的循环索引变量。
c、避免用Flag来命名状态变量。
d、用Is来命名逻辑变量,如:blnFileIsFound。通过这种给布尔变量肯定形式的命名方式,使得其它开发人员能够更为清楚的理解布尔变量所代表的意义。
e、如果需要对变量名进行缩写时,一定要注意整个代码中缩写规则的一致性。例如,如果在代码的某些区域中使用intCnt,而在另一些区域中又使用intCount,就会给代码增加不必要的复杂性。建议变量名中尽量不要出现缩写。
2.2.2 静态变量 1、选择有意义的名字,能快速地传达该变量的用途。
2、参照java驼峰命名法,采用全部大写的形式来书写,对于采用多词合成的变量采用“_”来连接各单词。如:USER_LIST
2.3 方法的命名 2.3.1 一般要求 1、选择有意义的名字,能快速地传达该方法的用途。
2、参照java驼峰命名法,首字母以小写开头,每个单词首字母大写(第一个单词除外)。
2.3.2 实际应用 1、方法表示一种行为,它代表一种动作,最好是一个动词或者动词词组或者第一个单词为一个动词。
2、属性方法:以get/set开头,其后跟字段名称,字段名称首字母大写。如:getUserName()
3、数据层方法:只能以insert(插入),delete(删除),update(更新),select(查找),count(统计)开头,其他层方法避免以这个5个单词开头,以免造成误解。
4、服务层方法,根据方法的行为命名,只描述方法的意义,而不采用方法的目的命名。比如系统的添加新用户,用户可以前台注册,也可以管理员后台添加,方法会被重用,所以最好不要用使用register,采用add会更好写。避免使用与web层相关的方法。
5、Web层方法最好是贴近web的语言,如register,login,logout等方法。
三 注释的书写规范 (Javadoc) Java除了可以采用我们常见的注释方式(//、/* */)之外,Java语言规范还定义了一种特殊的注释,也就是我们所说的Javadoc注释,以/**开头,而以*/结束, Javadoc 注释可以被自动转为在线文档,省去了单独编写程序文档的麻烦。 推荐使用。
Javadoc注释主要涉及范围:类、属性、方法。
例如:
复制代码 代码如下:
package org.ietf.jgss;
import java.net.InetAddress;
import java.util.Arrays;
/**
* 该类的整体性描述。
*
* @author 作者
* @version 1.0, 05/22/07
* @since 1.0
*/
public class ChannelBinding {
/**
* 对该变量的备注信息
*/
private InetAddress initiator;
/**
* 对该变量的备注信息
*/
private InetAddress acceptor;
/**
* 对该变量的备注信息
*/
private byte[] appData;
/**
* 对该类的构造函数的备注信息。
*
* @param initAddr 对参数的备注。
* @param acceptAddr对参数的备注。
* @param appData对参数的备注。
*/
public ChannelBinding(InetAddress initAddr, InetAddress acceptAddr,
byte[] appData) {
initiator = initAddr;
acceptor = acceptAddr;
if (appData != null) {
this.appData = new byte[appData.length];
java.lang.System.arraycopy(appData, 0, this.appData, 0,
appData.length);
}
}
/**
* 对该类的具体一函数的备注信息
*
* @param obj 参数的备注信息
* @return 返回值的备注信息
*/
public boolean equals(Object obj) {
if (this == obj)
return true;
if (! (obj instanceof ChannelBinding))
return false;
ChannelBinding cb = (ChannelBinding) obj;
return Arrays.equals(appData, cb.appData);
}
}四 其他书写规范
4.1 Jsp页面名称的书写规范 1.全部采用小写的英文字符和”_ ”组成。
2.整体采用模块名+操作的形式。如:user_view.jsp
3.Jsp页面尽可能与action的意思对应,如UserListAction 对应者user_list.jsp
相信看了这些案例你已经掌握了方法,更多精彩请关注php中文网其它相关文章!
相关阅读:
The above is the detailed content of Questions and answers about camel case naming and JS. For more information, please follow other related articles on the PHP Chinese website!
JavaScript in Action: Real-World Examples and ProjectsApr 19, 2025 am 12:13 AMJavaScript's application in the real world includes front-end and back-end development. 1) Display front-end applications by building a TODO list application, involving DOM operations and event processing. 2) Build RESTfulAPI through Node.js and Express to demonstrate back-end applications.
JavaScript and the Web: Core Functionality and Use CasesApr 18, 2025 am 12:19 AMThe main uses of JavaScript in web development include client interaction, form verification and asynchronous communication. 1) Dynamic content update and user interaction through DOM operations; 2) Client verification is carried out before the user submits data to improve the user experience; 3) Refreshless communication with the server is achieved through AJAX technology.
Understanding the JavaScript Engine: Implementation DetailsApr 17, 2025 am 12:05 AMUnderstanding how JavaScript engine works internally is important to developers because it helps write more efficient code and understand performance bottlenecks and optimization strategies. 1) The engine's workflow includes three stages: parsing, compiling and execution; 2) During the execution process, the engine will perform dynamic optimization, such as inline cache and hidden classes; 3) Best practices include avoiding global variables, optimizing loops, using const and lets, and avoiding excessive use of closures.
Python vs. JavaScript: The Learning Curve and Ease of UseApr 16, 2025 am 12:12 AMPython is more suitable for beginners, with a smooth learning curve and concise syntax; JavaScript is suitable for front-end development, with a steep learning curve and flexible syntax. 1. Python syntax is intuitive and suitable for data science and back-end development. 2. JavaScript is flexible and widely used in front-end and server-side programming.
Python vs. JavaScript: Community, Libraries, and ResourcesApr 15, 2025 am 12:16 AMPython and JavaScript have their own advantages and disadvantages in terms of community, libraries and resources. 1) The Python community is friendly and suitable for beginners, but the front-end development resources are not as rich as JavaScript. 2) Python is powerful in data science and machine learning libraries, while JavaScript is better in front-end development libraries and frameworks. 3) Both have rich learning resources, but Python is suitable for starting with official documents, while JavaScript is better with MDNWebDocs. The choice should be based on project needs and personal interests.
From C/C to JavaScript: How It All WorksApr 14, 2025 am 12:05 AMThe shift from C/C to JavaScript requires adapting to dynamic typing, garbage collection and asynchronous programming. 1) C/C is a statically typed language that requires manual memory management, while JavaScript is dynamically typed and garbage collection is automatically processed. 2) C/C needs to be compiled into machine code, while JavaScript is an interpreted language. 3) JavaScript introduces concepts such as closures, prototype chains and Promise, which enhances flexibility and asynchronous programming capabilities.
JavaScript Engines: Comparing ImplementationsApr 13, 2025 am 12:05 AMDifferent JavaScript engines have different effects when parsing and executing JavaScript code, because the implementation principles and optimization strategies of each engine differ. 1. Lexical analysis: convert source code into lexical unit. 2. Grammar analysis: Generate an abstract syntax tree. 3. Optimization and compilation: Generate machine code through the JIT compiler. 4. Execute: Run the machine code. V8 engine optimizes through instant compilation and hidden class, SpiderMonkey uses a type inference system, resulting in different performance performance on the same code.
Beyond the Browser: JavaScript in the Real WorldApr 12, 2025 am 12:06 AMJavaScript's applications in the real world include server-side programming, mobile application development and Internet of Things control: 1. Server-side programming is realized through Node.js, suitable for high concurrent request processing. 2. Mobile application development is carried out through ReactNative and supports cross-platform deployment. 3. Used for IoT device control through Johnny-Five library, suitable for hardware interaction.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 Chinese version
Chinese version, very easy to use

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Dreamweaver CS6
Visual web development tools

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Zend Studio 13.0.1
Powerful PHP integrated development environment






