Skip to content

Commit

Permalink
Add JavaScript style guide
Browse files Browse the repository at this point in the history
* Add initial JavaScript style guide
* Add ES6 to best practices via babel
  • Loading branch information
BlakeWilliams committed Mar 3, 2015
1 parent f71de09 commit d175383
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 1 deletion.
4 changes: 3 additions & 1 deletion best-practices/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,10 @@ Email

JavaScript
----------
* Use Coffeescript, ES6 with [babel], or another language that compiles to
JavaScript

* Use CoffeeScript.
[babel]: http://babeljs.io/

HTML
----
Expand Down
1 change: 1 addition & 0 deletions style/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ detailed, language/framework-specific style guides:
* [Git](git)
* [Haskell](haskell)
* [HTML](html)
* [JavaScript](javascript)
* [Objective C](objective_c)
* [Python](python)
* [Rails](rails)
Expand Down
24 changes: 24 additions & 0 deletions style/javascript/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
JavaScript
==========

[Sample](sample.js)

* Prefer ES6 classes over prototypes.
* Use strict equality checks (`===` and `!==`) except when comparing against
(`null` or `undefined`).
* Prefer [arrow functions] `=>`, over the `function` keyword except when
defining classes or methods.
* Use semicolons at the end of each statement.
* Prefer double quotes.
* Use `PascalCase` for classes, `lowerCamelCase` for variables and functions,
`SCREAMING_SNAKE_CASE` for constants, `_singleLeadingUnderscore` for private
variables and functions.
* Prefer [template strings] over string concatenation.
* Prefer promises over callbacks.
* Prefer array functions like `map` and `forEach` over `for` loops.
* Use `const` for declaring variables that will never be re-assigned, and `let`
otherwise.
* Avoid `var` to declare variables.

[template strings]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/template_strings
[arrow functions]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions
7 changes: 7 additions & 0 deletions style/javascript/sample.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
object = { spacing: true }

class Cat {
canBark() {
return false;
}
}

0 comments on commit d175383

Please sign in to comment.