简体   繁体   中英

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: 在此处输入图片说明

Why? I am using JSDoc on Gulp.

I ran into the same problem as the original poster, but I was extending the JSON global with copy() and equals() methods.

(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.)

Following FreeLightman's suggestion in the comments above, to simply add the following line, solves the problem for me.

/** @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.

Since this is many years after the original question, I will point out that I'm using JSDoc version 6.14.12.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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