MooTools类和JsDoc

时间:2010-05-05 17:57:08

标签: javascript class documentation mootools jsdoc

我有以下Moo课程:


Nem.Ui.Window = new Class({
    Implements: [Options, Events],

    options: {
        caption:    "Ventana",
        icon:       $empty,
        centered:   true,
        id:         $empty,
        width:      $empty,
        height:     $empty,
        modal:      false,
        desktop:    $empty,
        x:          $empty,
        y:          $empty,
        layout:     $empty
    },

    initialize: function(options)
    {
        this.setOptions(options);
        /* ... */
    },

    setHtmlContents: function(content)
    {
        /* ... */
    },

    setText: function(text)
    {
        /* ... */
    },

    close: function(win)
    {
        /* ... */
    },

    /* ... */
});

我想用JsDoc记录它。我读过您可以在@lends [class].prototype内使用new Class并使用initialize标记标记@constructs。我如何标记方法和事件?

I.E。:setHtmlContents应该是一种方法,close应该是一个事件。

此外,options下的元素可以以某种方式记录吗?

2 个答案:

答案 0 :(得分:5)

您可以使用@function标记方法,使用@event标记事件,但由于默认情况下会正确检测到某些功能,因此在您的情况下不需要@function标记。

options下的元素可以使用@memberOf记录在@memberOf Nem.Ui.Window#的示例中。然后,它们将在生成的JSDoc中显示为options.optionName

您的课程的完整文档版本将类似于

/** @class This class represents a closabe UI window with changeable content. */
Nem.Ui.Window = new Class(
/** @lends Nem.Ui.Window# */
{
    Implements: [Options, Events],

    /** The options that can be set. */
    options: {
        /**
         * Some description for caption.
         * @memberOf Nem.Ui.Window#
         * @type String
         */
        caption:    "Ventana",
        /**
         * ...
         */
        icon:       $empty,
        centered:   true,
        id:         $empty,
        width:      $empty,
        height:     $empty,
        modal:      false,
        desktop:    $empty,
        x:          $empty,
        y:          $empty,
        layout:     $empty
    },

    /**
     * The constructor. Will be called automatically when a new instance of this class is created.
     *
     * @param {Object} options The options to set.
     */
    initialize: function(options)
    {
        this.setOptions(options);
        /* ... */
    },

    /**
     * Sets the HTML content of the window.
     *
     * @param {String} content The content to set.
     */
    setHtmlContents: function(content)
    {
        /* ... */
    },

    /**
     * Sets the inner text of the window.
     *
     * @param {String} text The text to set.
     */
    setText: function(text)
    {
        /* ... */
    },

    /**
     * Fired when the window is closed.
     *
     * @event
     * @param {Object} win The closed window.
     */
    close: function(win)
    {
        /* ... */
    },

    /* ... */

});

我已经跳过@constructs initialize,因为它根本不会显示在文档中,我还没想出如何让它正常工作。< / p>

有关可用标记及其功能的详细信息,请参阅jsdoc-toolkit的TagReference上的wiki

答案 1 :(得分:0)

我终于使用自然文档解决了这个问题。

相关问题