Skip to content

Javascript style guide

xavijam edited this page Jun 4, 2012 · 9 revisions

Javascript CartoDB style guide

this is the style guide for javascript in cartodb

naming

  • GLOBALS_ARE_UPPERCASE_AND_UNDERSCORED
  • local variables are as short as you can and camelCase
  • use self to scope this
  • function and method names are camelCase
  • private methods start with underscore
  • class names are CamelCase (capitalized)

comments

every class or method should be commented. Ok. every class or method which is not clear should be commented

/**
 * Illustrates line wrapping for long param/return descriptions.
 * @param {string} foo This is a param with a description too long to fit in
 *     one line.
 * @return {number} This returns something that has a description too long to
 *     fit in one line.
 */
function method(foo) {
  return 5;
}

misc

  • variable declaration:
var a = 'a'
  , b = null
  , c;
  • we use semicolons (use jslint or similar to check)
Clone this wiki locally