Javascript 如何使用jsdoc工具包记录匿名函数(闭包)

Javascript 如何使用jsdoc工具包记录匿名函数(闭包),javascript,comments,closures,anonymous-function,jsdoc,Javascript,Comments,Closures,Anonymous Function,Jsdoc,我正在尝试使用JSDoc工具包记录我的代码。我的代码首先用一个自动执行的匿名函数包装。我到底该如何记录这些?我几乎花了一整天在这上面。JS文档不会识别匿名函数闭包中的任何内容,因为它不知道如何处理它。它中断了,我的任何评论都没有通过 我的代码看起来像这样 /** * @fileoverview BLA BLA BLA */ /** * This is where I don't know what to put. */ (function () { "use strict

我正在尝试使用JSDoc工具包记录我的代码。我的代码首先用一个自动执行的匿名函数包装。我到底该如何记录这些?我几乎花了一整天在这上面。JS文档不会识别匿名函数闭包中的任何内容,因为它不知道如何处理它。它中断了,我的任何评论都没有通过

我的代码看起来像这样

/** 
 * @fileoverview BLA BLA BLA
 */

/**
 * This is where I don't know what to put.
 */
 (function () {
     "use strict";

     /** or here */
     var stlib = function (param, param, param) {
         /** or here */
         var share = {
             /** or here */
             config: {
                 button: DOM Element,
                 property: blablabla
             },

             init: function () { ...some init code here}
         };

         share.init();
     };

     widgets.add("share", stlib);
 }());

谢谢大家!

您可以将@namespace与@name和@lend一起使用,如下所示:

/**
* @name MyNamespace
* @namespace Hold all functionality
*/
(function () {
    "use strict";
    /** @lends MyNamespace*/
    var stlib = function (param, param, param) { ...All of my code...};
}());
/**
 * @module foobar
 */

/**
* @function
* @author Baa
* @name hello 
* @description Output a greeting
* @param {String} name - The name of the person to say hello
*/
(function hello(name) {
    /**
     * @function
     * @author Baz
     * @inner
     * @private
     * @memberof module:foobar
     * @description Check if the argument is a string (see: {@link module:foobar~hello})
     * @param {String} string - The string
     * @returns {String} Returns true if string is valid, false otherwise
     */ 
    var isString = function checkString(string) { return typeof string === 'string'; };
    if (isString(name))
      console.log('Hello ' + name + '!');
}('Mr. Bubbles'));

不能直接记录嵌套函数。但你可以这样做:

/**
* @name MyNamespace
* @namespace Hold all functionality
*/
(function () {
    "use strict";
    /** @lends MyNamespace*/
    var stlib = function (param, param, param) { ...All of my code...};
}());
/**
 * @module foobar
 */

/**
* @function
* @author Baa
* @name hello 
* @description Output a greeting
* @param {String} name - The name of the person to say hello
*/
(function hello(name) {
    /**
     * @function
     * @author Baz
     * @inner
     * @private
     * @memberof module:foobar
     * @description Check if the argument is a string (see: {@link module:foobar~hello})
     * @param {String} string - The string
     * @returns {String} Returns true if string is valid, false otherwise
     */ 
    var isString = function checkString(string) { return typeof string === 'string'; };
    if (isString(name))
      console.log('Hello ' + name + '!');
}('Mr. Bubbles'));
这里我将
checkString
设置为private,并将其内部设置为描述性(因为不能描述嵌套函数),然后传入
-p
以记录私有函数。最后,我添加了一个指向父函数的链接以供参考

我认为
jsdoc
是不必要的挑剔,需要用更好的东西来代替。它是
javadoc
的一个端口,因此它有很多与Java相关的东西,但与JS无关,反之亦然。有一些非常常见的JS习惯用法,如闭包或嵌套函数,很难或不可能记录下来


我总是检查我的名字路径,并使用
--explain
标志进行调试。

我的道歉。这并不是我想要做的。我用更多信息更新了代码片段。谢谢你的回复!javascript中没有名称空间。这个构造甚至不起作用sense@Raynos它们不在语言中有什么区别?他们是jsdoc。也许这不是真正的语义,但我写的东西,它是有效的。@Microfed我觉得它不可读,然后我再次发现jsdoc是一个肮脏的java仿真,有太多的结构,根本不可读apply@Raynos是的,有许多构造不适用。许多在内部做完全相同的事情(例如@aguments和@extends)。你的工作是使用你认为有用的东西,而放弃所有其他东西。这是因为JSDoc完全是java isms,不适合JavaScript。只要写些合理的评论就行了谢谢你,rjmunro。我同意。我不认为它太本地化了。然而,从那时起,我就转到Docco进行文档编制。jashkenas.github.com/docco/你也可以去看看吗