JavaScript Naming Conventions, Coding Guidelines and Best Practices

  • Semicolons are always required.
  • Braces are always used to enclose the bodies of if/for/while/try statements.
  • Lines should be wrapped at a 120 column margin.
  • Indentation should be consistent. Use an indentation length of 2 spaces.
  • Double quotes (") are used rather than single quotes (').
  • All class names should be a combination of words with the first letter of each word capitalized.
  • The function names and method names should also be a combination of words with the first letter of each word capitalized except for the first word.
  • It is a very common practice to begin functions with get/set/is word depending upon whether the function is returning a value, setting a value or returning a boolean result.
  • All private member variables and methods of classes should be prefixed with "_" to distinguish them from public member variables.
  • All global objects should exist in namespaces.
  • All variables should be prefixed with a letter indicating the data type of the variable (Hungarian notation).

s - String
n - number
b - boolean
a - Array
o - object

Further, the first letter of each of the words should be capitalized.

posted on 2010-01-27 15:10  北冥有鱼,化而为鸟  阅读(334)  评论(3编辑  收藏  举报

导航