• Diff for "JavaScriptStyleGuide"
Differences between revisions 2 and 4 (spanning 2 versions)
Revision 2 as of 2012-12-06 01:41:41
Size: 998
Editor: baalexander
Comment:
Revision 4 as of 2013-03-19 00:15:19
Size: 942
Editor: baalexander
Comment:
Deletions are marked like this. Additions are marked like this.
Line 14: Line 14:
 * camelCase variables and function names
 *
CapitalCamelCase for classes
* [[http://en.wikipedia.org/wiki/Indent_style#Compact_control_readability_style|Compact Control]] indention
 * camelCase variables and function names, CapitalCamelCase for classes, CAPS for namespaces, CAPS for constants
Line 19: Line 17:
 * `===` for comparisons  * Triple equals (`===`) for comparisons

ROS JavaScript Style Guide

This page defines a style guide to be followed in writing JavaScript code for ROS. This guide applies to all ROS code, both core and non-core.

For Python, see the Python Style Guide and for C++, see the C++ Style Guide

Coding Style

A quick summary is:

  • 2 space indention
  • camelCase variables and function names, CapitalCamelCase for classes, CAPS for namespaces, CAPS for constants

  • Semicolons are good
  • JSDoc for documentation

  • Triple equals (===) for comparisons

An example can be worth a thousand words:

/**
 * Performs an example task.
 *
 * @param foo - task selector
 */
function exampleTask(foo) {
  var myVar = 'My message';

  if (foo === 'Do this') {
    anotherExampleTask(myVar);
  }
  else {
    someOtherTask(myVar);
  }
}

Wiki: JavaScriptStyleGuide (last edited 2014-11-07 15:16:53 by Russell Toris)