Variable and Function Style
- variables and functions : use camelCase
- var score;
- var myDate;
- function loanCalculator() { ... }
- Yahoo, Google, Java, DOM, JQuery
- Always use block - even if one line
- Define functions before calling them to make them readable (though you don't have to)
- Open curly braces on the same line
- Always use semicolons to end a statement
- Always use var when declaring a variable
- JavaScript Minifier
- JavaScript Checker/Linter
- JQuery
Brace Style
//
// JavaScript's own ability to insert what it thinks are missing
// semicolons on lines that don't have them
// Place the opening curly brace at the same line of keyword, if, while
// and always use block as possible
if (x) {
} else {
}
// compare to Pascal or Allman style, Avoid.
if (x)
{
}
else
{
}
Note: Check Yahoo, Google, Mozilla for "javascript style guidelines"
Useful Links
No comments:
Post a Comment