JavaScript has no official style guide, but maintaining a consistent style within a project is important. For this book, I’ve adopted the following (very common) conventions:
Two-space indentation
camelCase identifiers
Semicolons at the end of every expression, except function definitions
More esoterically, I’ve adopted a special convention for indentation in a chain of function calls, based on a proposal by Reg Braithwaite. The rule is, essentially, that two function calls in a chain have the same indentation level if and only if they return the same object. So, for instance, I might write the following:
| $('#container > ul li.inactive') |
| .slideUp(); |
jQuery’s slideUp method returns the same object that it ...
No credit card required