-
Notifications
You must be signed in to change notification settings - Fork 26.8k
Some additional notes on naming conventions #165
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -995,7 +995,7 @@ | |
|
||
## Naming Conventions | ||
|
||
- Avoid single letter names. Be descriptive with your naming. | ||
- Avoid single letter names. Be descriptive with your naming. Names representing types should be nouns. Names representing methods should be verbs or verb phrases. | ||
|
||
```javascript | ||
// bad | ||
|
@@ -1009,7 +1009,7 @@ | |
} | ||
``` | ||
|
||
- Use camelCase when naming objects, functions, and instances | ||
- Use camelCase when naming objects, functions, and instances. Abbreviations and acronyms should also use camel case when used as a name. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Acronyms and initialisms should be properly capitalized - ie, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On top of reverting the line, would be good to add a new line with your comment |
||
|
||
```javascript | ||
// bad | ||
|
@@ -1020,12 +1020,20 @@ | |
name: 'Bob Parr' | ||
}); | ||
|
||
// bad | ||
function parseJSON() {}; | ||
var XMLDocument; | ||
|
||
// good | ||
var thisIsMyObject = {}; | ||
function thisIsMyFunction() {}; | ||
var user = new User({ | ||
name: 'Bob Parr' | ||
}); | ||
|
||
// good | ||
function parseJson() {}; | ||
var xmlDocument; | ||
``` | ||
|
||
- Use PascalCase when naming constructors or classes | ||
|
@@ -1050,6 +1058,16 @@ | |
}); | ||
``` | ||
|
||
- Use Screaming Snake Case for constants | ||
|
||
```javascript | ||
// bad | ||
var some_constant = 5; | ||
|
||
// good | ||
var SOME_CONSTANT = 5; | ||
``` | ||
|
||
- Use a leading underscore `_` when naming private properties | ||
|
||
```javascript | ||
|
@@ -1089,7 +1107,7 @@ | |
} | ||
``` | ||
|
||
- Name your functions. This is helpful for stack traces. | ||
- Name your functions. This is helpful for stack traces. Note this is not necessary for class methods. | ||
|
||
```javascript | ||
// bad | ||
|
@@ -1101,6 +1119,20 @@ | |
var log = function log(msg) { | ||
console.log(msg); | ||
}; | ||
|
||
// bad | ||
var MyObj = { | ||
log: function log(msg) { | ||
console.log(msg); | ||
} | ||
}; | ||
|
||
// good | ||
var MyObj = { | ||
log: function(msg) { | ||
console.log(msg); | ||
} | ||
}; | ||
``` | ||
|
||
**[⬆ back to top](#table-of-contents)** | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
JS doesn't really have "methods" - could this be
functions
instead?