最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Document constructor with multiple signatures - Stack Overflow

programmeradmin1浏览0评论

I'd like to know how can I define two signatures for the constructor with jsdoc:

makeClass("Person",
/** @lends Person */
{
    /**
        @constructs
        @param {int} p1
    */
    /**
        @constructs
        @param {string} p1
    */
    constructor: function () {

    },

    /**
        @name Person.prototype.func
        @function
        @param {object} arg arg desc
    */
    /**
        @name Person.prototype.func^2
        @function
        @param {int} arg arg desc
        @param {int} arg2 arg2 desc
    */
    func: function () {

    }
});

This produces one constructor with {string} p1.

Thanks for your help

I'd like to know how can I define two signatures for the constructor with jsdoc:

makeClass("Person",
/** @lends Person */
{
    /**
        @constructs
        @param {int} p1
    */
    /**
        @constructs
        @param {string} p1
    */
    constructor: function () {

    },

    /**
        @name Person.prototype.func
        @function
        @param {object} arg arg desc
    */
    /**
        @name Person.prototype.func^2
        @function
        @param {int} arg arg desc
        @param {int} arg2 arg2 desc
    */
    func: function () {

    }
});

This produces one constructor with {string} p1.

Thanks for your help

Share Improve this question edited May 16, 2012 at 9:50 János Roden asked May 16, 2012 at 9:17 János RodenJános Roden 1681 silver badge11 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 5

DocumentJS, the documentation tool used/created by the JavascriptMVC project has released a new "@signature" annotation that allows you to annotate multiple signatures for the same method.

I can't find much documentation but according to the source (edited for brevity) it looks straight forward:

   /**
     * @signature `observe.attr()`
     * @return {Object<String, *>} an object with all the properties in this `can.Observe`.
     * 
     * @signature `observe.attr(key)`
     * @param {String} key the property to read
     * @return {*} the value assigned to _key_.
     *
     * @signature `observe.attr(key, value)`
     * @param {String} key the property to set
     * @param {*} the value to assign to _key_.
     * @return {can.Observe} this Observe, for chaining
     */
   attr: function( attr, val ) {

JSDoc doesn't have a concept parable to the Visual Studio XML Doc multiple signatures. One option would be to document parameters as having multiple possible types, and marking some optional.

/**
 * @param {Number|Object} arg Description of arg
 * @param {Number} [arg2] Description of arg2
 */
发布评论

评论列表(0)

  1. 暂无评论