使用smartdoc/yuidoc语法写NodeJS服务器端注释 - 自动生成文档

如何编写文件块注释

/**
 * @filename Demo
 *
 * @module ServerModule
 *
 * @author OnO<corn.mars@ono.lol>
 * @version 1
 * @time 2015/8/26 16:48
 */

module.exports = function (app) {
    return new DemoHandler(app);
};

如何编写对象注释 - 包括类属性

/**
 * Demo Handler
 *
 * @class DemoHandler
 * @param {Object} app
 * @constructor
 */
function DemoHandler(app) {
    /**
     * App Instance
     *
     * @property app
     * @type {Object}
     */
    this.app = app;
}

如何编写类方法注释

/**
 * Demo handler
 *
 * @method shot
 * @for DemoHandler
 *
 * @param {Object} msg message from client
 * @param {Object} session
 * @param {Function} next next stemp callback
 *
 * @async
 * @return {Null}
 */
DemoHandler.prototype.shot = function (msg, session, next) {
    var ret = {
    code: 500
    };

    var uid = msg.uid;
    if (!uid) {
    return next(null, ret);
    }

    // get all connectors
    var connectors = this.app.getServersByType('connector');
    if (!connectors || connectors.length === 0) {
    return next(null, ret);
    }

    // select connector
    var dispatcher = require("app/util/dispatcher");
    var res = dispatcher.dispatch(uid, connectors);

    ret.host = res.host;
    ret.port = res.clientPort;
    next(null, ret);

    session.on("closed", onShot.bind(null, self.app));
};

如何编写普通方法注释

/**
 * When Shot Called
 *
 * @event onShot
 * @for DemoHandler
 *
 * @param {Object} app current application
 * @param {Object} session current session object
 */
var onShot = function (app, session) {
    if (!session || !session.uid) {
    return;
    }
    app.rpc.chat.chatRemote.kick(session, session.uid, app.get("serverId"), session.get("rid"), null);
};
Donate - Support to make this site better.
捐助 - 支持我让我做得更好.