How to document this using jsdoc? [closed]
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 5 years ago.
Improve this questionI'd like to know how to document this type of class using jsdoc
:
var MyObject = (function(){
var that = {};
function privateFunction(){};
that.publicFunction = function(){};
that.publicField = "foo";
return that;
})();
There are a number of things named JSDoc, but using closure compiler annotations which work with jsdoc toolkit, you can use @constructor
to mark MyClass
as a constructor.
/** @constructor */
var MyClass = ...;
Then you can make it clear that that
is of the nominal type MyClass
though obviously that nominal type won't work with instanceof
.
/** @type MyClass */
var that = /** @type {MyClass} */ {};
The first @type
establishes the type of the declaration, and the second is a type assertion/cast for the value.
With the methods you can use the @this
annotation.
/** @this MyClass */
that.publicFunction = function () { ... };
精彩评论