目录
当前位置: 首页 > 文档资料 > JSDoc 中文文档 >

@returns

优质
小牛编辑
127浏览
2023-12-01

描述: 记录一个函数的返回值。

别名:

  • return

概述

@returns 标签描述一个函数的返回值。语法和@param类似。

例子

返回值的类型,例如:

/**
 * Returns the sum of a and b
 * @param {Number} a
 * @param {Number} b
 * @returns {Number}
 */
 function sum(a, b) {
     return a + b;
}

返回值的类型和描述,例如:

/**
 * Returns the sum of a and b
 * @param {Number} a
 * @param {Number} b
 * @returns {Number} Sum of a and b
 */
 function sum(a, b) {
     return a + b;
}

返回值可以有不同的类型,例如:

/**
 * 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.
 */
 function sum(a, b, retArr) {
     if (retArr) {
             return [a, b, a + b];
    }    
    return a + b;
}