Javascript JSDoc CommonJS,导出传递到IIFE的对象

Javascript JSDoc CommonJS,导出传递到IIFE的对象,javascript,jsdoc,jsdoc3,Javascript,Jsdoc,Jsdoc3,更新:@spenibus帮助我得出结论,这可能是JSDoc本身的问题。我将我的发现添加到他们的GitHub上@斯皮尼布斯找到了一个解决方案,但它需要稍微改变IIFE的版本 我在CommonJS模块中使用IIFE,以便能够使用CommonJS,并在不存在接口module.exports的情况下,将接口分配给窗口对象。我如何正确地对此进行记录,以便传入的导出对象被视为module.exports /** * This is a description * @module someModule

更新:@spenibus帮助我得出结论,这可能是JSDoc本身的问题。我将我的发现添加到他们的GitHub上@斯皮尼布斯找到了一个解决方案,但它需要稍微改变IIFE的版本

我在CommonJS模块中使用IIFE,以便能够使用CommonJS,并在不存在接口module.exports的情况下,将接口分配给窗口对象。我如何正确地对此进行记录,以便传入的导出对象被视为module.exports

/**
 * This is a description
 * @module someModule
 */
(function (exports) {

    /**
     * Returns true if something.
     * @param {String} type
     * @returns {boolean}
     * @static
     */
    var isSomething = function isSomething(type){
        return true;
    };

    exports.isSomething = isSomething;

})(
    //if exports exists, this is a node.js environment so attach public interface to the `exports` object
    //otherwise, fallback to attaching public interface to the `window` object
    (typeof exports === 'undefined') ?
         window
        : exports
);
虽然这似乎很重要,但我们还没有取得任何进展

我看了一下,虽然有希望,但它没有提供相同的JSDoc输出

然后我尝试了一些简单的方法,让我在脑海中播放FF7胜利主题,也就是说,它奏效了:

/**
 * This is a description
 * @module someModule
 */

(function() {

    // export to window when not used as a module
    if(typeof exports === 'undefined') {
        var exports = window;
    }

    /**
     * Returns true if something.
     * @param {String} type
     * @returns {boolean}
     * @static
     */
    exports.isSomething = function(type){
        return true;
    };
})();
在projectdir上使用
jsdoc./
会产生与我没有使用IIFE一样的输出。基本思想是始终有一个名为
的对象导出
,只需修改它引用的内容即可

Nodejs试验 输出:

--Testing nodejs--
{ isSomething: [Function] }
"--html script test--"
"function (type){
    return true;
}"
Html脚本测试 更新2015-08-13 05:10+0000
在IIFE中移动了窗口导出,以避免html脚本中出现额外的
导出
var


什么不起作用?有错误吗?因为这段代码中有一些语法问题,但逻辑似乎很好。@spenibus没有错误,但它无法识别通过三元运算符传入IIFE的“exports”对象是公共接口。生成的文档在HTML页面的顶部只有“someModule This is a description”(这是一个描述),除此之外,HTML中没有提到公共的“isSomething”方法,也没有任何其他附加到“exports”(导出)的公共接口方法/对象忽略语法错误,当我复制代码并删除任何特定于项目的内容(公司不喜欢共享他们的代码)时,这是一个错误。我将其归结为以下内容(加上@module声明),它仍然不会生成除模块名称/描述以外的任何内容。FWIW,我正在通过“gulp JSDoc”gulp任务(函数(导出){exports.isSomething=function(type){return true;};}(typeof exports==='undefined'?窗口:导出)),使用jsdocstrap 3.3.0-alpha5和DocStrap主题;您刚才提供的代码仍然存在相同的语法问题,即括号不匹配。哇,是的,您是对的。我修改了它,所以文件只包含@module标记和这段代码,仍然不起作用。(函数(导出){exports.isSomething=function(type){return true;};})(导出的类型=='undefined'?窗口:导出);如何调用isSomething
?它是一个静态方法,因此类似于var someModule=require('someModule');someModule.isSomething('foo'))
<script src="module.js"></script>
<script>
    console.log('--html script test--');
    console.log(isSomething.toString());
</script>
"--html script test--"
"function (type){
    return true;
}"