@use JSDoc

同義語

構文

@returns [{type}] [description]

概要

@returns タグは、関数が返す値を記述します。

ジェネレーター関数を記述する場合は、このタグではなく @yields タグ を使用してください。

型付きの戻り値
/**
 * 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);
    });
}