Naming Conventions are necessary to enhance the readability of the Code, so that you can understand what you want to express at a Glance. Standards are rules that make the code easier for later maintenance, it can also greatly improve the development efficiency.
JS naming rules
Naming Conventions are necessary to enhance the readability of the Code, so that you can understand what you want to express at a Glance. Standards are rules that make the code easier for later maintenance, it can also greatly improve the development efficiency. A normal website has a lot of JS Code. If you do not follow certain rules during the compilation process, you will not be able to understand what you wrote after writing it. This is a very troublesome thing, therefore, we need to develop a good habit of writing code during regular exercises.
Generally, the Hungarian or camper method is used.
The principle of the Hungarian naming method: variable name = property + Type + object description. The key is to use one or more lower-case letters as the prefix, followed by a combination of one or more upper-case words, which indicates the purpose of the variable.
The first word starts with a lowercase letter, and then the first letter of each word is capitalized. For example, myFirstName and myLastName, the variable name looks like a camper. The key to the hump method is: in addition to the first word, the size of the first letter of other words. The variable name and function name are composed of uppercase and lowercase letters, and the logical breakpoint can be formed by underlines, this improves the readability of the Code.
What naming conventions should be based on personal preferences or company regulations. Note: you cannot use reserved words or names that are too long to remember. Avoid using two similar variable names. The following are the prefixes of commonly used Hungarian naming methods:
Type |
Prefix |
Type |
Instance |
Array |
A |
Array |
AItems (Project) |
String |
S |
String |
SUserName |
Function |
Fn |
Function |
FnHandler (Processing Program) |
Object |
O |
Object |
Op |
Integer |
I |
Integer |
IItemCount (Project count) |
Floating Point Number |
F |
Float |
FPrice) |
Boolean Value |
B |
Boolean |
BIsComplete (completed) |
Regular Expression |
Re |
RegExp |
ReEmailCheck (email detection) |
The above is the JS naming convention: details of the Hungarian or camper method. For more information, see other related articles in the first PHP community!