@use JSDoc

構文

@exports <moduleName>

JSDoc 3.3.0 以降では、<moduleName>module: プレフィクスを含めることができます。以前のバージョンでは、このプレフィクスは省略する必要があります。

概要

"exports" オブジェクトまたは "module.exports" プロパティ以外のものをエクスポートする JavaScript モジュールを文書化する場合は、@exports タグを使用します。

特別な "exports" オブジェクトを使用するモジュールでは、@exports タグは必要ありません。JSDoc はこのオブジェクトのメンバーがエクスポートされていることを自動的に認識します。同様に、JSDoc は Node.js モジュール内の特別な "module.exports" プロパティを自動的に認識します。

CommonJS モジュール
/**
 * A module that says hello!
 * @module hello/world
 */

/** Say hello. */
exports.sayHello = function() {
    return 'Hello world';
};
Node.js モジュール
/**
 * A module that shouts hello!
 * @module hello/world
 */

/** SAY HELLO. */
module.exports = function() {
    return "HELLO WORLD";
};
オブジェクトリテラルをエクスポートする AMD モジュール
define(function() {

    /**
     * A module that whispers hello!
     * @module hello/world
     */
    var exports = {};

    /** say hello. */
    exports.sayHello = function() {
        return 'hello world';
    };

    return exports;
});
コンストラクターをエクスポートする AMD モジュール
define(function() {
    /**
     * A module that creates greeters.
     * @module greeter
     */

    /**
     * @constructor
     * @param {string} subject - The subject to greet.
     */
    var exports = function(subject) {
        this.subject = subject || 'world';
    };

    /** Say hello to the subject. */
    exports.prototype.sayHello = function() {
        return 'Hello ' + this.subject;
    };

    return exports;
});

モジュールが "exports" または "module.exports" 以外の名前のオブジェクトをエクスポートする場合は、@exports タグを使用して何がエクスポートされているかを示します。

オブジェクトをエクスポートする AMD モジュール
define(function () {

    /**
     * A module that says hello!
     * @exports hello/world
     */
    var ns = {};

    /** Say hello. */
    ns.sayHello = function() {
        return 'Hello world';
    };

    return ns;
});