- use camelCase everywhere, except constants which are
UPPER_CASE_WITH_UNDERSCORE
- start constructor name with upper case letter
- do not use short variable names
- 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
(
We use 4 spaces for identation. No deep identation, i.e. use this way:
do.something.awesome(function(imdone) {
imdone();
});
instead of this
do.something.awesome(function(imdone) {
imdone();
});
Use done
, next
, callback
, cb
or fn
as callback param name.
Do not use bind, do not save this
in self
or that
variable. Use meaningful
variable name, for example:
Listing.prototype.update = function(done) {
var listing = this;
listing.products.update(function() {
listing.update(done);
});
};
Do not use "
, use '
for strings.
Right:
[
'hello',
'world',
{ foo: 'bar' }
];
Wrong:
[ 'hello' , 'world' , { 'foo': 'bar' , 'bar': 'baz' } ]
Do not indent, start with dot:
$('#element')
.addClass('active')
.show();
Use them