Show Menu

Closure JSDoc Cheat Sheet by

The subset of JSDoc supported by Google Closure Compiler.
javascript     google     documentation     jsdoc     closure

JSDoc Tags for Functions

@const­ructor
Function is a constr­uctor (can new)
@depre­cated
Function is deprec­ated
@extends {Type}
Function inherits Type
@imple­ments {Type}
Function imple­ments Type (with @const­ruc­tor)
@inher­itDoc
Function has same JSDoc as superc­lass
@interface
Function is interface (no new)
@nosid­eef­fects
Can be removed if return value not used
@override
Function overrides superc­lass
@param {Type} varname Descri­ption
Function takes varname of Type
@private
Function is private (same file or static­/in­stance members)
@protected
Function is protected (same file or static­/in­stance of subcla­sses)
@return {Type} Descri­ption
Function returns Type
@this {Type}
In Function, this is Type

JSDoc Tags for Properties

@const
Property is constant
@define
Property can be overridden by compiler
@depre­cated
Property is deprec­ated
@enum {Type}
Property is an enum of Type (default number)
@expose
Property not optimized by compiler
@lends {objec­tName}
Keys of object are same as property of other object (see: http:/­/co­de.g­oo­gle.co­m/p­/js­doc­-to­olk­it/­wik­i/T­agL­ends)
@private
Property is private
@protected
Property is protected
@type {Type}
Property is {Type}
 

JSDoc Type Defini­tions

{boolean}
True
{number}
1
{string}
'monkey'
{Object}
{}
{Array}
[]
{Window}
defined type Window
{goog.u­i.M­enu}
defined type goog.u­i.Menu
{Array.<s­tri­ng>}
['a','­b','c']
{Objec­t.<­string, number­>}
{'a':1, 'b':2}
{(numb­er|­boo­lean)}
1 or True
{{myNum: number, myObject}}
Record with property myNum {number} and myObject {Object}
{Array.<{­len­gth­}>}
Array of {Objects} with property length
{?number}
{number} or null
{!Object}
{Object} but never null
{funct­ion­(st­ring, boolean)}
Function with params and unknown return value
{funct­ion(): number}
Function retur­ning number
{funct­ion­(th­is:­goo­g.u­i.Menu, string)}
Function where this is goog.u­i.Menu
{funct­ion­(ne­w:g­oog.ui.Menu, string)}
Function takes string, creates new goog.u­i.Menu
{funct­ion­(st­ring, ...[nu­mber])}
Function takes string then optional number s
@param {...nu­mber} var_args
Variable number of parameters of type number
@param {number=} opt_ar­gument
Optional parameter of type number
{funct­ion­(?s­tring=, number=)}
Function with optional parame­ters
{*}
Variable can take any type
{?}
Variable can take any type and don't type check
 

JSDoc Example

/**
* Creates an instance of Circle.
*
* @const­ructor
* @this {Circle}
* @param {number} r The desired radius of the circle.
*/
function Circle(r) {
/* @private / this.r­adius = r;
/* @private / this.c­irc­umf­erence = 2 Math.PI r;
}

/**
* Creates a new Circle from a diameter.
*
* @param {number} d The desired diameter of the circle.
* @return {Circle} The new Circle object.
*/
Circle.fr­omD­iameter = function (d) {
return new Circle(d / 2);
};

/**
* Calculates the circum­ference of the Circle.
*
* @depre­cated
* @this {Circle}
* @return {number} The circum­ference of the circle.
*/
Circle.pr­oto­typ­e.c­alc­ula­teC­irc­umf­erence = function () {
return 2 Math.PI this.r­adius;
};

/**
* Returns the pre-co­mputed circum­ference of the Circle.
*
* @this {Circle}
* @return {number} The circum­ference of the circle.
*/
Circle.pr­oto­typ­e.g­etC­irc­umf­erence = function () {
return this.c­irc­umf­erence;
};

/**
* Find a String repres­ent­ation of the Circle.
*
* @override
* @this {Circle}
* @return {string} Human-­rea­dable repres­ent­ation of this Circle.
*/
Circle.pr­oto­typ­e.t­oString = function () {
return "A Circle object with radius of " + this.r­adius + ".";
};

Download the Closure JSDoc Cheat Sheet

2 Pages
//media.cheatography.com/storage/thumb/killermonkeys_closure-jsdoc.750.jpg

PDF (recommended)

Alternative Downloads

Share This Cheat Sheet!

Like this cheat sheet? Check out our sponsors!

Readable.io is a collection of tools to make your writing better. More readable content means higher conversion rates and better reader engagement. Measure website and document readability, measure keyword density and more!

Click Here To Get Started!

 

Comments

No comments yet. Add yours below!

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          Related Cheat Sheets

          AngularJS Cheat Sheet
          JavaScript Cheat Sheet