使用jsDoc记录jQuery参数类型的正确方法是什么

时间:2022-10-22 11:29:05

I'm trying to document my program with the jsdoc syntax for myself and the people that will have to look at my code. I'm also trying to improve my skills. For a parameter of the jQuery type I'm a little puzzled. I know that's an object, but a fairly common in my program, so I think I should first declare a typedef for the jQuery type, then use it as my parameter type. So I ask, would it be the correct way to do it?

我正在尝试用自己的jsdoc语法和必须查看我的代码的人来记录我的程序。我也在努力提高自己的技能。对于jQuery类型的参数,我有点困惑。我知道这是一个对象,但在我的程序中相当常见,所以我想我应该首先为jQuery类型声明一个typedef,然后将它用作我的参数类型。所以我问,这是正确的方法吗?

    /**
     * DOM object referenced by jQuery
     * @typedef {jQuery} $jQueryDomObject
     */

    /**
    * SOAP call that does ...
    *
    * @param {string} code Some desc ...
    * @param {callback} fnctVa Some desc ...
    * @param {$jQueryDomObject} $attrib Input field that ...
    */
    myfunction = function (code, fnctVa, $attrib) {};

Update : also found on SO this question, somewhat similar : How can I get jsdoc to mark my param as a jquery object?

更新:在SO上也发现了这个问题,有点类似:我如何让jsdoc将我的param标记为jquery对象?

2 个解决方案

#1


17  

For a parameter that is a jQuery object, I often just do:

对于作为jQuery对象的参数,我经常这样做:

@param {jQuery} foo

And do not further define what jQuery is. It is known well enough. However, if you want, you can do this with jsdoc 3:

并且不要进一步定义jQuery是什么。众所周知。但是,如果需要,可以使用jsdoc 3执行此操作:

/**
 * jQuery object
 * @external jQuery
 * @see {@link http://api.jquery.com/jQuery/}
 */

/**
 * SOAP call that does ...
 *
 * @param {string} code Some desc ...
 * @param {callback} fnctVa Some desc ...
 * @param {external:jQuery} $attrib Input field that ...
 */
var myfunction = function (code, fnctVa, $attrib) {};

#2


3  

I also saw on github/js3doc:

我也在github / js3doc上看到过:

@param {jQuery object} obj The jQuery object you're looking for.

or github/js3doc

或者github / js3doc

@param {module:jquery} jquery Some desc...

#1


17  

For a parameter that is a jQuery object, I often just do:

对于作为jQuery对象的参数,我经常这样做:

@param {jQuery} foo

And do not further define what jQuery is. It is known well enough. However, if you want, you can do this with jsdoc 3:

并且不要进一步定义jQuery是什么。众所周知。但是,如果需要,可以使用jsdoc 3执行此操作:

/**
 * jQuery object
 * @external jQuery
 * @see {@link http://api.jquery.com/jQuery/}
 */

/**
 * SOAP call that does ...
 *
 * @param {string} code Some desc ...
 * @param {callback} fnctVa Some desc ...
 * @param {external:jQuery} $attrib Input field that ...
 */
var myfunction = function (code, fnctVa, $attrib) {};

#2


3  

I also saw on github/js3doc:

我也在github / js3doc上看到过:

@param {jQuery object} obj The jQuery object you're looking for.

or github/js3doc

或者github / js3doc

@param {module:jquery} jquery Some desc...