Skip to content

Latest commit

 

History

History
115 lines (102 loc) · 2.36 KB

jsdoc.md

File metadata and controls

115 lines (102 loc) · 2.36 KB

JSDoc

Documenting which parameters a function accepts

/**
 * @param {(string|string[])} name - User's name, or an array of names
 */
/**
 * @param {*} name - User's name
 */

___

Documenting a parameter's properties

/**
 * Assign the project to an employee.
 *
 * @param {Object} employee - The employee who is responsible for the project.
 * @param {string} employee.name - The name of the employee.
 * @param {string} employee.department - The employee's department.
 */
Project.prototype.assign = function(employee) {
    // ...
};

___

Documenting optional parameters

/**
 * Greet the user
 *
 * @param {string} [name] - Name of person to say hello to
 * @returns {string} Greeting
 */
function hello(name) {
  name = name || "visitor";
  alert("Hello " + name + "!");
}

___

Documenting an unknown number of parameters

/**
 * Return the sum of all numbers passed to the function
 *
 * @param {...number} num - A positive or negative number.
 */
function sum(num) {
    var i = 0, n = arguments.length, t = 0;
    for (; i < n; i++) {
        t += arguments[i];
    }
    return t;
}

___

Returning a value from a function

/**
 * Greet the user
 *
 * @param {string} name - Name of person to say hello to
 * @returns {string} Greeting
 */
function hello(name) {
  return "Hello "+name +"!";
}

___

Identifying a function as a constructor

/**
 * Create a new book
 *
 * @constructor
 * @param {string} title - The title of the book.
 * @param {string} author - The author of the book.
 */
function Book(title, author) {
  // ...
}

var book = new Book("The Da Vinci Code", "Dan Brown");