Using JSDoc to quickly generate annotation documents is great.

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.