8000
Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Latest commit

 

History

History
90 lines (69 loc) · 2.58 KB

File metadata and controls

90 lines (69 loc) · 2.58 KB

Conventions

These coding conventions are a work-in-progress, and should be considered "DRAFT."

Most of these coding conventions are taken from others, including:

Files

  • JavaScript files should be stored in and delivered as .js files

Language rules

  • Variable declarations must start with var
  • All variable declarations should be the first statements in a function body
  • The use of global variables should be avoided
  • If global variables are absolutely necessary, they should be added to the NPMap namespace
  • All JavaScript expressions must end with a semi-colon
  • When a function is to be invoked immediately, the entire invocation expression should be wrapped in parens so that it is clear that the value being produced is the result of the function and not the function itself (see Example 1 below)

Style rules

Naming conventions

  • Case: functionNamesLikeThis, variableNamesLikeThis, ClassNamesLikeThis, and CONSTANTS_LIKE_THIS
  • Be as descriptive as possible
  • Private variables or functions should begin with underscores (_privateFunction, _privateVariable)
  • Optional arguments should start with opt_

Strings

  • Use single quotes, not double ('i am a string')

Formatting

  • Do not use tabs anywhere. Use 2 spaces indent for each level of scope
  • Wrapped lines should be indented 4 spaces

Comments

  • Should follow JSDoc conventions
  • Each function must be commented (purpose, @param, @return) - see Example 2 below
  • Copyright, author, license, and short description of the file should be at the top of the code - see Example 3 below

Examples

1:


var aString = (function() {
  return 'i am a string';  
});

2:


/**
 * A description of this function
 * @param {ClassOptions} [opts]
 * @return {String}
 */

3:


/**
 * @name NameOfClass
 * @version 1.1
 * @author Nate Irwin
 * @copyright (c) 2011 U.S. National Park Service
 * @fileoverview A description of this class.
 */

/*
 * The code license goes here.
 */
0