/** * The built in string object. * @external String * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String|String} */
/** * Create a ROT13-encoded version of the string. Added by the `foo` package. * @function external:String#rot13 * @example * var greeting = new String('hello world'); * console.log( greeting.rot13() ); // uryyb jbeyq */
/** * A jQuery plugin to make stars fly around your home page. * @function external:"jQuery.fn".starfairy */
例如,扩展一个外部类:
1 2 3 4 5 6 7 8 9 10 11
/** * The built-in class for sending HTTP requests. * @external XMLHttpRequest * @see https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest */
/** * Extends the built-in `XMLHttpRequest` class to send data encoded with a secret key. * @class EncodedRequest * @extends external:XMLHttpRequest */
/** * 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) { // ... };
例如,描述参数的属性值在数组中:
1 2 3 4 5 6 7 8 9
/** * Assign the project to a list of employees. * @param {Object[]}employees - The employees who are responsible for the project. * @param {string}employees[].name - The name of an employee. * @param {string}employees[].department - The employee's department. */ Project.prototype.assign = function (employees) { // ... };
/** * Returns the sum of all numbers passed to the function. * @param {...number}num - A positive or negative number. */ functionsum(num) { var i = 0, n = arguments.length, t = 0; for (; i < n; i++) { t += arguments[i]; } return t; }
例如,参数接受一个回调函数:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/** * This callback type is called `requestCallback` and is displayed as a global symbol. * * @callback requestCallback * @param {number}responseCode * @param {string}responseMessage */
/** * Does something asynchronously and executes the callback on completion. * @param {requestCallback}cb - The callback that handles the response. */ functiondoSomethingAsynchronously(cb) { // code }
@returns
描述: 记录一个函数的返回值。
返回值的类型和描述,例如:
1 2 3 4 5 6 7 8 9
/** * Returns the sum of a and b * @param {Number}a * @param {Number}b * @returns {Number}Sum of a and b */ functionsum(a, b) { return a + b; }
返回值可以有不同的类型,例如:
1 2 3 4 5 6 7 8 9 10 11 12 13
/** * Returns the sum of a and b * @param {Number}a * @param {Number}b * @param {Boolean}retArr If set to true, the function will return an array * @returns {Number|Array}Sum of a and b or an array that contains a, b and the sum of a and b. */ functionsum(a, b, retArr) { if (retArr) { return [a, b, a + b]; } return a + b; }
@constructs
描述: 这个函数成员将成为类的构造函数。
@lends:将一个字面量对象的所有属性标记为某个标识符(类或模块)的成员。
@param:标明这个标识属于哪个父级标识。
例如, @constructs 和 @lends 结合使用:
1 2 3 4 5 6 7 8 9 10 11 12 13
var Person = makeClass( /** @lends Person.prototype */ { /** @constructs */ initialize: function (name) { this.name = name; }, /** Describe me. */ say: function (message) { returnthis.name + " says: " + message; }, } );
/** * See {@link MyClass} and [MyClass's foo property]{@link MyClass#foo}. * Also, check out {@link http://www.google.com|Google} and * {@link https://github.com GitHub}. */ functionmyFunction() {}
@tutorial
描述: 链接到一个教程。
下面的例子显示了提供给{@tutorial}标签链接文本的所有方式,例如:
1 2 3 4 5 6
/** * See {@tutorial gettingstarted} and [Configuring the Dashboard]{@tutorial dashboard}. * For more information, see {@tutorial create|Creating a Widget} and * {@tutorial destroy Destroying a Widget}. */ functionmyFunction() {}