Skip to content

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 35 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Copy link
Collaborator

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?


```javascript
// bad
Expand All @@ -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.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Acronyms and initialisms should be properly capitalized - ie, XML or xml, but never Xml - since the purpose is readability, not appeasing an automatic camelcase parsing algorithm. Can you revert this line?

Copy link

Choose a reason for hiding this comment

The 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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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)**
Expand Down