代码之家  ›  专栏  ›  技术社区  ›  Ian Elliott

jsdoc中对象的正确标记

  •  3
  • Ian Elliott  · 技术社区  · 15 年前

    在jsdoc中记录这种样式的对象的正确方法是什么:

    /**
    
    */
    
    var strings = 
    {
        /**
    
        */  
        stripHTML: function(html)
        {
            //does something
        },
        /**
    
        */
        validHTML: function(html)
        {
            //does something else
        }
    }
    

    2 回复  |  直到 15 年前
        1
  •  2
  •   Jonathan Fingland    15 年前

    我会用@namespace来表示“字符串”

    这些方法将简单地使用@function(尽管jsdoc很清楚它们是什么)

    在您的特定示例中,您可能希望使用以下内容:

    /**
        describe purpose
    */
    String.prototype.stripHTML = function()
    {
        //does something with this
    }
    
    /**
        describe purpose
    */
    String.prototype.validHTML = function()
    {
        //does something else with this
    }
    

    然后像这样使用:

    var str = "bob<br/>";
    str = str.stripHTML();
    
        2
  •  2
  •   Billy Moon    13 年前

    虽然通过设置原型来定义对象成员函数有很好的理由,但有时这并不实际。我想我会发布一个不会重新考虑代码的答案。它使用了与@Jonathan的答案相同的想法。

    /**
     * @namespace
     * Custom String functions
     */
    var strings = 
    {
        /**
         * Strips the HTML away
         */  
        stripHTML: function(html)
        {
            //does something
        },
    
        /**
         * Ensures the HTML is valid
         */
        validHTML: function(html)
        {
            //does something else
        }
    }
    

    示例来自: JSDoc-Toolkit 这正是我想要的。