Skip to content

Latest commit

 

History

History
75 lines (52 loc) · 1.66 KB

JavaScript Style Guide.md

File metadata and controls

75 lines (52 loc) · 1.66 KB

JavaScript Style Guide

  • Best practices:

http://learn.jquery.com/style-guide/ http://contribute.jquery.org/style-guide/js/ https://github.com/stevekwan/best-practices/blob/master/javascript/gotchas.md

TypeScript

  • Use static analysis to validate code

  • TSLint at checkin

  • Microsoft has implementation

  • Reference:

https://slack.engineering/typescript-at-slack-a81307fa288d https://www.jetbrains.com/help/idea/2017.1/typescript-support.html

Comments

  • Inline comments should have a leading space and be complete sentences.
  • Example:
\\ Bind the click event to the function.
  • Use JSDoc comments:

http://usejsdoc.org/ https://github.com/jsdoc3/jsdoc

  • Use @name, @constructor, @param, and @returns.

http://usejsdoc.org/tags-name.html http://usejsdoc.org/tags-constructor.html http://usejsdoc.org/tags-param.html http://usejsdoc.org/tags-returns.html

  • Include a description of the object, full sentence.
  • Example:
/*-----------------------------------------------------------------------------*/
 * The ReferencePlugin object.
 * 
 * @constructor
 * @param {string}
 *          id - Id of the div to target for html replacement.
 * @param {int}
 *          interval - How often to run update() to refresh the content.
 * @param {string}
 *          exampleParameter - Parameter that will be printed out later in a method.
 *
 * @return {string}
 *           returnValue - What gets return, null if nothing.
 */
function ReferencePlugin( id, interval, exampleParameter ) {
	
}
  • Place any hacks or quick work arounds in shame.js

  • Always run jslint against code before committing

http://www.jslint.com/