【问题标题】:MooTools Classes and JsDocMooTools 类和 JsDoc
【发布时间】:2011-02-16 01:31:36
【问题描述】:

我有以下 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 记录它。我读到你可以在new Class 中使用@lends [class].prototype,并用@constructs 标签标记initialize。如何标记方法和事件?

IE:setHtmlContents 应该是一个方法,close 应该是一个事件。

另外,options 下的元素能否以某种方式记录下来?

【问题讨论】:

    标签: javascript class documentation mootools jsdoc


    【解决方案1】:

    您可以用@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)
        {
            /* ... */
        },
    
        /* ... */
    
    });
    

    我已经跳过了initialize@constructs,因为那时它根本不会出现在文档中,而且我还没有弄清楚如何让它正常工作。

    有关可用标签及其功能的更多信息,请参阅 jsdoc-toolkit 的 wiki 上的 TagReference

    【讨论】:

      【解决方案2】:

      我终于通过使用 Natural Docs 解决了这个问题。

      【讨论】:

      • 这根本不是原始问题的答案。这充其量是一种解决方法。
      • 请随意回答,然后:)
      猜你喜欢
      • 2012-04-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-14
      • 2014-02-11
      • 2020-04-02
      • 2012-05-10
      • 2011-03-09
      相关资源
      最近更新 更多