Sometimes we need to build a document to record some code comments in JS, such as some public functions, or some classes, in team work, the document interface is also essential, the traditional way is somewhat inconvenient, here is a tool called JSDoc, it can be used to generate annotations document.
Although it is said that it can generate annotations to the document, but also not any comments can be, we need to follow its specifications to write.
First we use NPM to download it.
NPM Install Jsdoc-g
The format of the JSDoc is this.
/**
* Two numbers added
* @param {Number} num1 addition
* @param {Number} num2 is added
* @returns {Number} and
*/
function Add (num1,num2) {
return NUM1 + num2;
}
First the comment is/** start, end with */end.
@: There is a certain role in JSDoc, that is, it has a set of labeling rules. Such as:
@param {type} n1 description
Param: Represents the function parameter {type} parameter value description
@returns {Type} description
Returns: Return value description
There's a lot more.
generate JSDoc Document:cmd inside executes JSDoc xx.js
An out directory is generated under the current directory with a index.html that opens to see the resulting results.
See no, still very clear.
And there's a tank constructor inside it. The code is like this.
/**
* Tank Class
* @constructor
* @param {Number} x coordinate X
* @param {Number} y-coordinate y
* @param {Number} dire direction
* @param {array} colors a set of colors
*/
function Tank (x,y,dire,colors) {
this.x = x;
This.y = y;
Speed
This.steep = 5;
Direction
This.dire = dire;
Tank Color
This.colors = colors;
Move direction
This.moveup = function () {
this.y-= This.steep;
This.dire = 0;
};
This.moveright = function () {
this.x+= This.steep;
This.dire = 1;
};
This.movedown = function () {
this.y+= This.steep;
This.dire = 2;
};
This.moveleft = function () {
this.x-= This.steep;
This.dire = 3;
};
}
@constructor represents a constructor, you can see clearly what the result looks like.
This is the introduction of a few more commonly used, of course, there are many methods, here is not introduced, you can look at the official documents or search the relevant tutorials, here is just for everyone to enter a door.
The
uses JSDoc to quickly generate annotation documents, which is great.