JSDoc 中文网

Synonyms

语法

🌐 Syntax

@returns [{type}] [description]

概述

🌐 Overview

@returns 标签记录函数返回的值。

🌐 The @returns tag documents the value that a function returns.

如果你正在记录一个生成器函数,请使用 @yields 标签 而不是这个标签。

🌐 If you are documenting a generator function, use the @yields tag instead of this tag.

示例

🌐 Examples

具有类型的返回值
/**
 * 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;
}
返回一个承诺
/**
 * Returns the sum of a and b
 * @param {number} a
 * @param {number} b
 * @returns {Promise<number>} Promise object represents the sum of a and b
 */
function sumAsync(a, b) {
    return new Promise(function(resolve, reject) {
        resolve(a + b);
    });
}