【发布时间】:2015-10-18 05:37:36
【问题描述】:
更新:@speibus 帮助我得出结论,这可能是 JSDoc 本身的问题。我在他们的 GitHub 上将我的发现添加到 this open issue。 @spenibus 找到了解决方案,但它需要稍微改动的 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
);
【问题讨论】:
-
什么不起作用?有什么错误吗?因为这段代码有一些语法问题,但逻辑似乎很好。
-
@spenibus 没有错误,但它无法将通过三元运算符传入 IIFE 的“导出”对象识别为公共接口。生成的文档在 HTML 页面顶部只有“someModule This is a description”,但没有其他内容,HTML 中没有提到公共“isSomething”方法,也没有任何其他公共接口方法/对象附加到“出口”
标签: javascript jsdoc jsdoc3