A doclet serves as a JSDoc entity that is accessible to plugins and templates. Many individuals interact with JSDoc annotations instead, such as:
so.js
/**
* This serves as a JSDoc comment
*/
Showcasing the doclets:
# npx jsdoc -X so.js
[
{
"kind": "package",
"longname": "package:undefined",
"files": [
"/workspace/dev/tmp/so.js"
]
}
]
For instance:
/**
* @return {boolean}
*/
function bar() {
return true;
}
Doclets:
# npx jsdoc -X so.js
[
{
"comment": "/**\n * @return {boolean}\n */",
"meta": {
"range": [
29,
62
],
"filename": "so.js",
"lineno": 4,
"columnno": 0,
"path": "/workspace/dev/tmp",
"code": {
"id": "astnode100000002",
"name": "bar",
"type": "FunctionDeclaration",
"paramnames": []
}
},
"returns": [
{
"type": {
"names": [
"boolean"
]
}
}
],
"name": "bar",
"long name": "foo",
"kind": "function",
"scope": "global",
"params": []
},
{
"kind": "package",
"longname": "package:undefined",
"files": [
"/workspace/dev/tmp/so.js"
]
}
]
It is evident that JSDoc does not require you to explicitly state that bar
is a function. A plethora of details can be inferred from the source code and these are captured within a doclet.
The JSDoc documentation refers to "virtual JSDoc comments" in certain sections. These correspond to isolated JSDoc blocks that are not immediately followed by JavaScript code. In fact, it's possible to generate a complete API documentation solely using virtual JSDoc comments without any tangible code.