Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/1602/coding-style-guide


https://github.com/1602/coding-style-guide

Last synced: about 1 month ago
JSON representation

Awesome Lists containing this project

README

        

### Naming

- use camelCase everywhere, except constants which are `UPPER_CASE_WITH_UNDERSCORE`
- start constructor name with upper case letter
- do not use short variable names

### Spaces

- operators should be surrounded with spaces
- anonyous function should not have space between `function` and `(`
- maned function should have not have space between function name and `(`

### Identation

We use 4 spaces for identation. No deep identation, i.e. use this way:

```javascrtipt
do.something.awesome(function(imdone) {
imdone();
});
```

instead of this

```javascrtipt
do.something.awesome(function(imdone) {
imdone();
});
```

### Callback names

Use `done`, `next`, `callback`, `cb` or `fn` as callback param name.

### Callback context binding, using `self` and `that`

Do not use bind, do not save `this` in `self` or `that` variable. Use meaningful
variable name, for example:

```javascrtipt
Listing.prototype.update = function(done) {
var listing = this;
listing.products.update(function() {
listing.update(done);
});
};
```

### Strings

Do not use `"`, use `'` for strings.

### Objects, arrays formatting

Right:

```
[
'hello',
'world',
{ foo: 'bar' }
];
```

Wrong:

[ 'hello'
, 'world'
, { 'foo': 'bar'
, 'bar': 'baz'
}
]

### Chaining

Do not indent, start with dot:

```javascrtipt
$('#element')
.addClass('active')
.show();
```

### Semicolons

Use them