Show Menu
Cheatography

The subset of JSDoc supported by Google Closure Compiler.

JSDoc Tags for Functions

@const­ructor
Function is a constr­uctor (can new)
@depre­cated
Function is deprecated
@extends {Type}
Function inherits Type
@imple­ments {Type}
Function implements Type (with @const­ructor)
@inher­itDoc
Function has same JSDoc as superclass
@interface
Function is interface (no new)
@nosid­eef­fects
Can be removed if return value not used
@override
Function overrides superclass
@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 deprecated
@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 returning 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 parameters
{*}
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 + ".";
};
               
 

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