Based on idiomatic.js
but with less whitespace inside parenthesis.
Always use 2 spaces for indentation (no tabs).
Never leave trailing whitespace.
Leave one blank line at the end of the file.
Keep lines under 80 characters long.
Never mix quotation marks in a project. Prefer single quotes, but be consistent.
Prefer === over == for comparisons (=== does not coerce types).
Don't rely on automatic semicolon insertion. Use semicolons after every simple statement and don't put more than one statement per line.
Coding Style Guide
Coding Style Guide
Coding Style Guide
Constructor Functions
Coding Style Guide
Coding Style Guide
Coding Style Guide
Naming
Always use meaningful names. An exception are commonly used names as conventions
(i with for loops, e for events in handlers, err for errors in try/catch)
Coding Style Guide
Comments
Single line above the code that is subject.
Multiline is good.
End of line comments are prohibited!
JSDoc style is good, but requires a significant time investment.
From Crockford: It is important that comments be kept up-to-date. Erroneous comments can make programs even harder to read and understand.
Make comments meaningful. Focus on what is not immediately visible.
From MDN:
"Each object has an internal link to another object called its prototype. That prototype object has a prototype of its own, and so on until an object is reached with null as its prototype. null, by definition, has no prototype, and acts as the final link in this prototype chain."
Prototypal Inheritance
The Object.create method can be used to make new objects which
prototype is the object passed as the first parameter.
Prototypal Inheritance
JavaScript also supports a form of "classical" inheritance through
constructor functions.
The Module Pattern
Modules provide a clean way to separate large applications into smaller pieces that interact between them.
They allow us to encapsulate data and functionalities (like private and public properties and methods in "classical" object-oriented language).