You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
epicmonkey edited this page Apr 13, 2015
·
5 revisions
Idiomatic.js
Idiomatic.js is the base code style document. Nonetheless there are a couple of personal preferences listed below.
General rules
This project uses these rules:
* Spaces only, no tabs
* Indent size to 2 spaces characters
* Eliminating end of line whitespace
* Eliminating blank line whitespace
* Double quotes are preferable
* No semicolons. Semicolons are cancer of javascript
Beautiful syntax
A. Parens, Braces, Linebreaks
// Bad
if(condition) doSomething();
// Good
if (condition)
doSomething();
// Bad
if ( condition ) {
// statements
}
// Good
if (condition) {
// statements
}
// Bad
var a;
var b;
// Good
var a,
b;
// Even better (comma first)
var a
, b;
B. Assignments, Declarations, Functions ( Named, Expression, Constructor )
// 2.B.1.1
// Variables
// Bad
var a;
a = 10;
// Good
var a = 10;
// 2.B.2.1
// Named Function Declaration
function foo(arg1, argN) {
}
// Usage
foo(arg1, argN);
C. Exceptions, Slight Deviations
// 2.C.1.1
// Functions with callbacks
foo(function() {
// Note there is no extra space between the first paren
// of the executing function call and the word "function"
});
// Function accepting an array, no space
foo(["alpha", "beta"]);