Introduction to the use of JSDoc

Source: Internet
Author: User
JsDocToolkit is a tool used to format js descriptions into documents. Developers can easily export documents by writing comments according to the JsDoc specifications. It is a JsDoc generation tool recommended by google. JsDoc Toolkit recently released version 2.3.2, which mainly fixes previous versions.
If you need to use Ant, JsDoc also has an Ant plug-in: JsDoc Toolkit Ant Task
Download JsDoc Toolkit2.3.2: http://jsdoc-toolkit.googlecode.com/files/jsdoc_toolkit-2.3.2.zip
Command Name Description
@ Param @ argument specify the Parameter Name and description to describe a function parameter.

@ Returns the return value of the description function
@ Author indicates the author of the Code.
@ Deprecated indicates that a function has been discarded and will be permanently deleted in future code versions. Avoid using this code
@ See creates an HTML link pointing to the description of the specified class
@ Version: Specifies the release version.
@ Requires create an HTML link pointing to the specified class required by this class
@ Throws @ exception describes the types of exceptions that a function may throw.
{@ Link} creates an HTML link pointing to the specified class. This is similar to @ see, but {@ link} can be embedded in the comment text.
@ Fileoverview this is a special mark. If this tag is used in the first document block of the file, specifying the remaining part of the document block will be used to provide an overview of the file.
@ Class provides information about the class, which is used in the document of the constructor.
@ Constructor: it is clear that a function is a constructor of a class.
@ Type specifies the return type of the function.
@ Extends indicates that one class derives from another class. JSDoc can detect this information by itself. However, in some cases, this flag must be used.
@ Private indicates that a class or function is private. Private classes and functions will not appear in the HTML document unless the -- private command line option is provided when JSDoc is run.
@ Final indicates that a value is a constant value. Remember that JavaScript cannot really ensure that a value is a constant.
@ Ignore JSDoc ignore the function with this mark

JsDoc: A js document generation tool that extracts comments from the javascript program source code, such as classes, methods, and members to form an API help document that matches the source code.
Java open-source project http://www.jsdoctoolkit.org/, which is a powerful built-in criptfile generation tool.
Next we will end how to use it.
Download the tool library.
Here we use jsdoc_toolkit-2.1.0.zip, which is also the highest version.
Decompress the file. You can see the readme.txt file.
Here are detailed instructions for use. [It seems that we can introduce it here. Of course, you can continue reading]
Here we need to create a javascript document through the command line.
Java-jar jsrun. jar app/run. js-a-e = GB18030-t = templates/jsdoc test/*. js
Of course, if the command line method is troublesome, we can create a. bat file on our own.
Copy the above content to the file and execute it.
The following is a brief explanation of the parameters.
-A indicates all methods.
-E indicates the encoding root of the corresponding file. Here, GB18030 corresponds to UTF-8 by default.
-T indicates the Document Style template for producing doc
Test/*. js indicates all javascript files in the test directory.
After the execution is complete, the document results are output to the/out/jsdoc directory by default. Of course, this directory can also be defined.
Specific parameters can be used
Java-jar jsrun. jar app/run. js -- help
.
The result is as follows:

The Code is as follows:


OPTIONS:
-A or -- allfunctions
Include all functions, even uninitialized ented ones.
-C or -- conf
Load a configuration file.
-D = Or -- directory =
Output to this directory (defaults to "out ").
-D = "myVar: My value" or -- define = "myVar: My value"
Multiple. Define a variable, available in JsDoc as JSDOC. opt. D. myVar.
-E = Or -- encoding =
Use this encoding to read and write files.
-E = "REGEX" or -- exclude = "REGEX"
Multiple. Exclude files based on the supplied regex.
-H or -- help
Show this message and exit.
-N or -- nocode
Ignore all code, only document comments with @ name tags.
-O = Or -- out =
Print log messages to a file (defaults to stdout ).
-P or -- private
Include symbols tagged as private, underscored and inner symbols.
-Q or -- quiet
Do not output any messages, not even warnings.


Next we will create the js file under test
Simple Method Annotation
Myjs. js

The Code is as follows:


/**
* @ FileOverview simple method annotation example
* @ Author llying
* @ Version 0.1
*/

/**
* @ Description Addition
* @ Param {Num} num1 addend
* @ Param {Num} num2 is added
* @ Return {Num} result
*/
Function add (num1, num2 ){
Return num1 + num2;
}
/**
* @ Description Subtraction
* @ Param {Num} num1 subtrahend
* @ Param {Num} num2 subtrahend
* @ Return {Num} result
*/
Function minus (num1, num2 ){
Return num1-num2;
}


Class Method Annotation
Myjs2.js

The Code is as follows:


/**
* @ FileOverview simple Class Object annotation example
* @ Author llying
* @ Version 0.1
*/
/**
* @ Author llying
* @ Constructor Person
* @ Description a Person class
* @ See The llying.
* @ Example new Parent ("Zhang San", 15 );
* @ Since version 0.1
* @ Param {String} username
* @ Param {Num} age
*/
Function Person (username, age)
{
/**
* @ Description {Sting} Name
* @ Field
*/
This. username = username;
/**
* @ Description {Num} age
* @ Field
*/
This. age = age
/**
* @ Description the "say" content is displayed.
* @ Param {String} content
*/
This. say = function (content)
{
Alert (this. username + "say:" + content );
}
/**
* @ Description returns an object in json format.
* @ Return {String} In json format
* @ See Person # say
*/
This. getJson = function (){
Return "{name:" + this. username + ", age" + this. age + "}";
}
}


Now we can run java-jar jsrun. jar app/run. js-a-e = GB18030-t = templates/jsdoc test/*. js

So far, our js document has been generated. We don't need to envy JavaDoc either.

We only list common tags. For more tags, visit the official website.
Http://code.google.com/p/jsdoc-toolkit/wiki/TagReference
Related Article

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.