简体   繁体   English

使用 JSDoc 记录原型扩展函数

[英]Documenting Prototype Extension Functions with JSDoc

I have the following bit of code:我有以下代码:

/** @module Array */

/**
 * Returns this model's attributes as...
 *
 * @memberof Array.prototype
 * @function
 * @name each
**/
Array.prototype.each = function( callback ) {

    var context = this;

    for( var i = 0; i < context.length; i++ ) {
        callback( context[ i ] );
    }

}

When I document this with JSDoc, I get:当我用 JSDoc 记录这个时,我得到: 在此处输入图片说明

Why?为什么? I am using JSDoc on Gulp.我在 Gulp 上使用 JSDoc。

I ran into the same problem as the original poster, but I was extending the JSON global with copy() and equals() methods.我遇到了与原始海报相同的问题,但我使用copy()equals()方法扩展了JSON全局。

(Since there is some debate in the comments above, I will clarify: When I say "having the same problem," I mean that the JSDoc comments I placed before the JSON.copy() and JSON.equals() methods did not appear anywhere in my generated documentation, which was a problem not only because that documentation was lost, but also because no other documentation could link to the JSON.copy() or JSON.equals() methods.) (由于上面的评论中有一些争论,我将澄清:当我说“有同样的问题”时,我的意思是我放在JSON.copy()JSON.equals()方法之前的 JSDoc 评论没有出现我生成的文档中的任何地方都有问题,这不仅是因为该文档丢失了,还因为没有其他文档可以链接到JSON.copy()JSON.equals()方法。)

Following FreeLightman's suggestion in the comments above, to simply add the following line, solves the problem for me.按照 FreeLightman 在上面评论中的建议,只需添加以下行,即可为我解决问题。

/** @class JSON */

And by "solves the problem," I mean that there is now a page in my generated documentation that is specifically for the JSON object, and it contains the desired documentation for the copy() and equals() members, and I can link to those members from elsewhere in my documentation.通过“解决问题”,我的意思是我生成的文档中有一个页面专门用于 JSON 对象,它包含copy()equals()成员所需的文档,我可以链接到我文档中其他地方的那些成员。

Since this is many years after the original question, I will point out that I'm using JSDoc version 6.14.12.由于这是在原始问题之后多年,我将指出我使用的是 JSDoc 版本 6.14.12。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM