Skip to content

Commit 2ca5a9a

Browse files
committed
Some additional notes on naming conventions including recommendations on abbreviations, acronyms, constants and class methods.
1 parent 731ae10 commit 2ca5a9a

File tree

1 file changed

+35
-3
lines changed

1 file changed

+35
-3
lines changed

README.md

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -995,7 +995,7 @@
995995

996996
## Naming Conventions
997997

998-
- Avoid single letter names. Be descriptive with your naming.
998+
- Avoid single letter names. Be descriptive with your naming. Names representing types should be nouns. Names representing methods should be verbs or verb phrases.
999999

10001000
```javascript
10011001
// bad
@@ -1009,7 +1009,7 @@
10091009
}
10101010
```
10111011

1012-
- Use camelCase when naming objects, functions, and instances
1012+
- Use camelCase when naming objects, functions, and instances. Abbreviations and acronyms should also use camel case when used as a name.
10131013

10141014
```javascript
10151015
// bad
@@ -1020,12 +1020,20 @@
10201020
name: 'Bob Parr'
10211021
});
10221022
1023+
// bad
1024+
function parseJSON() {};
1025+
var XMLDocument;
1026+
10231027
// good
10241028
var thisIsMyObject = {};
10251029
function thisIsMyFunction() {};
10261030
var user = new User({
10271031
name: 'Bob Parr'
10281032
});
1033+
1034+
// good
1035+
function parseJson() {};
1036+
var xmlDocument;
10291037
```
10301038

10311039
- Use PascalCase when naming constructors or classes
@@ -1050,6 +1058,16 @@
10501058
});
10511059
```
10521060

1061+
- Use Screaming Snake Case for constants
1062+
1063+
```javascript
1064+
// bad
1065+
var some_constant = 5;
1066+
1067+
// good
1068+
var SOME_CONSTANT = 5;
1069+
```
1070+
10531071
- Use a leading underscore `_` when naming private properties
10541072

10551073
```javascript
@@ -1089,7 +1107,7 @@
10891107
}
10901108
```
10911109

1092-
- Name your functions. This is helpful for stack traces.
1110+
- Name your functions. This is helpful for stack traces. Note this is not necessary for class methods.
10931111

10941112
```javascript
10951113
// bad
@@ -1101,6 +1119,20 @@
11011119
var log = function log(msg) {
11021120
console.log(msg);
11031121
};
1122+
1123+
// bad
1124+
var MyObj = {
1125+
log: function log(msg) {
1126+
console.log(msg);
1127+
}
1128+
};
1129+
1130+
// good
1131+
var MyObj = {
1132+
log: function(msg) {
1133+
console.log(msg);
1134+
}
1135+
};
11041136
```
11051137

11061138
**[⬆ back to top](#table-of-contents)**

0 commit comments

Comments
 (0)