JSDOC

xiaoxiao2021-04-10  409

HREF = "stylesheet.css" type = "text / css" rel = "stylesheet" />

.comment {

COLOR: # 000066;

}

.comment_emph {

Color: # ff0000

}

JSDOC - JavaScript Documentation Tool

Introduction Installation Usage Tag Reference Frequently Asked Questions More Information

Introduction JSDoc is a tool that parses inline documentation in JavaScript source files, and produces an documentation of the JavaScript code. This is typically in the form of HTML (example), but XML and XMI (UML) export are also supported. JSDoc is based on the (very successful) javadoc tool that was created for the same purpose for the Java programming language. JSDoc is primarily intended for libraries of object-oriented JavaScript files, although it also works with procedural code. There is a basic ability to determine inheritance built into the parser, although some more obscure dynamic constructs will not be understood (for example, defining a method to set one class as the superclass of another) Anyone familiar with the javadoc tool will be able to use JSDoc right away;. for anyone Else It is a us Simple matter to get started. JSDOC PICKS UP on Comments That Are Opened with a slash backed by Two stars (/ **), and close (* /).

TOP

Installation JSDoc is implemented in Perl, as as such, requires the perl executable This should not be a problem for Linux / Unix users, but Windows users will probably have to install a perl runtime;.. ActivePerl is recommended JSDoc is distributed as a gzipped tarball, and can be downloaded from the JSDoc project page. Once you have downloaded JSDoc-xx.tgz, just unpack it (tar zxf JSDoc-xx.tgz on Linux / Unix, use WinZip on Windows), and you're ready to go. you can immediately try out JSDoc on the included test.js JavaScript file by going into the JSDoc directory and entering the command perl jsdoc.pl test.jsThis should output a set of HTML files in a directory called js_docs_out. If you get An Error Message Right Away That Looks Something Like Can't Locate Html / Template.pm in @inc ......

then you will need to install the HTML :: Template Perl module Luckily, this is a very trivial operation thanks to the CPAN In a Linux / Unix / POSIX-style operating system, open a terminal and run the following command as root..: # Perl -mcpan -e 'install html :: template'

If You're Running Windows and ActivePerl, Open A CommMand Prompt Window and Enter The Following Command: C: C: /> PPM

THIS WILL Start The Perl Package Manager; at The PPM Prompt, Enter The Following Two Commands (PPM> Is The PPM Prompt): PPM> Install HTML-Template

PPM> quit

JSDoc Should Run WITHOUT Problems Now.

TOP

Usage The general idea of ​​JSDoc is to pick up the form and documentation of code. A major part of JSDoc's functionality is based around documentation strings embedded in JavaScript code. The definitive reference to writing documentation strings for Java (with a large amount of carry- over to JSDoc) can be found at the javadoc reference page JSDoc currently supports a subset of javadoc's '@' -.. prefixed attributes, but the parser is customizable (as explained later) An example JavaScript file (test.js) is included with The JSDoc Distribution. Most FunctionAlity Of JSDoc Can Be Seen With Script File, However for the Impatient A Small (AND Incomplete) Example of A Common USAGE OF JSDOC IS Shown Below / **

* Shape Is An Abstract Base Class. It is defined Simply

* to have have something to inherit from for geometric

* SUBCLASSES

* @constructor

* /

Function shape (color) {

THIS.COLOR = Color;

}

// bind the shape_getcolor method to the shape class

Shape.Prototype.getColor = shape_getcolor;

/ **

* Get the name of the color for this shape

* @returns a color string for this shape

* /

Function shape_getcolor () {

Return this.color;

}

/ **

* Circle Is A Subclass of Shape

* /

Function Circle (RADIUS) {

THIS.RADIUS = RADIUS;

}

/ **

* A Very Rough Value for Pi

* /

Circle.pi = 3.14;

/ **

* Get the radius of this circle

* @returns the radius of this circle

* /

Function circle_getradius () {

Return this.radius;

}

// Circle Is A Subclass of Shape

Circle.Prototype = New Shape (NULL);

One important difference between javadoc and JSDoc is that JSDoc deals with a much more dynamic language that javadoc. For example, in JavaScript there are many different ways to make one class a subclass of another. The JSDoc parser is able to catch some of these methods , but for particularly dynamic scripts the parser will not be able to do it all on its own. for that reason, JSDoc is customizable with a file called .jsdoc_config that resides in the JSDoc install directory. in this configuration file, JSDoc's behaviour can be customized for any kind of '@' - prefixed attribute Although this configuration file actually contains Perl code, simple customizations can be done by someone with minimal experience with Perl.JSDoc also uses a several non-javadoc '@' - attributes:. @constructor and @private are two of the most important ones. As noted above, JavaScript has the capability to be a much more dynamic language than Java. The JSDoc parser can usually find class constructors on it's own, But There Area Some Situations When It Needs Some Additional Assistance. For this reason, it is a good practice to always include the @constructor tag in the documentation for a class constructor, as shown Below:

/ **

* Nothing is a class what represents Nothing

* @constructor

* /

Function Nothing () {

// ... Initialization ...

}

The @Private Attribute SIMPLY Displays The Marked Method As Being Private. To Get More Information on The Use of the Jsdoc.pl Executable Itself, Run It with The --help CommandLine Option.

TOP

Tag Reference The following is a summary of the supported tags ( '@' - attributes) that are supported by JSDoc For actual examples of the usage of these tags, please see the test.js JavaScript file that is included in the JSDoc distribution.. @Paramprovide Information About a Function Parameter. A DataType Indicator Can Be Added Between Curly Braces with this tag, as follows: / **

* @Param {string} paramnameTer this is a string parameter

* /

@argumentSynonym for @param @returnProvide information about the return value of a function. @returnsSynonym for @return @authorProvide information about the author of a JavaScript file or a function. @deprecatedSignify that a function or class is deprecated, and should not be used IF Possible. @seelink to another class or function That iv, tris tag can place @see #methodname

To Link to Another Class: @see classname

To Link to a Specific Method of Another Class: @see classname #METHODNAME

@versionShow the Version Number of the current file or class @requiresdefine a dependency Upon another class. The syntax for this tag is askN Follows: @Requires OtherclassName this is text to be shown

@ThrowSshow That a Method Can throw a certin type @Throws ExceptionType this is the label text

@exceptionSynonym for @throws @linkThis is a powerful tag that can be used to link to a large number of other pages It is also the only tag that can be used in the description text of a documentation string before the '@' -. tag Section. The usage is very Similar to this of the @see tag, but the entire tag is wrapped in curly braces. for example: / *** this utility method is also a member of the {@link string} Class,

* in the form of the {@link string # utility} method.

* /

@fileoverviewThis is a special-use tag. If the first block of documentation in a file starts with a @fileoverview tag, the rest of the documentation block will be used to provide a file overview in the documentation. @classThis tag is used in a . constructor's documentation block to provide information about the actual class The included documentation will then not be included in the constructor's documentation @constructorSignify that a function is the constructor for a class @typeShow the return type of a function for example:... / * *

* This function returns a string.

* @Return the name of the capital user

* @Type String

* /

@extendsUsed to show that a class is a subclass of another class. JSDoc is often quite good at picking this up on its own, but in some situations this tag is required. @privateSignify that a function or class is private. Private classes and functions . will not be available in the documentation unless JSDoc is run with the --private commandline option @finalFlag a value as being a final (constant) value @memberShow that a function is a member of a given class:. / **

* @MEMBER MyClass

* /

Function Somefunc () {

}

@ IgnoreTell Jsdoc to Totally ignore this method. @BaseForce JSDOC To View The Current Class Constructor As a Subclass of The Class Given As The Value To this Tag: / *** This Is A Subclass of Shape

* @constructor

* @Base Shape

* /

Function circle () {

// ...

}

@addonmark a function as being an "addon" to a core javascript fun: / **

* This is an addon function to somecoreclass Which IS

* NOT Defined within Our Own Sources.

* @addon

* /

Somecoreclass.somefunction = function () {

// ...

} @ExecExperimental! Force JSDoc to "execute" this method as part of its preprocessing step, in the same way that class contructors are executed. This can allow attributes to be added to a class from within a function.

TOP

FREQUENTLY Asked Questions

I get an error message That Says can't location html / template.pm in @inc ....... What's going on? This means That You don't have the html :: template perl module installed. Luckily, IT'S very easy to remedy this problem;. see the Installation section of this page I've found a bug in JSDoc What should I do Go to the JSDoc Project Page and register a bug report You can also send information about the bug to.?. the JSDoc-user mailing list. But just before you do that, please make sure that it's actually a bug that we're talking about, and not just JSDoc acting differently that what you were expecting. JSDoc segfaults! What should I do? This is a tough one to answer. JSDoc uses a lot of recursive regular expressions, and sometimes a certain combination of a certain build of perl and a certain JavaScript file will cause perl to segfault while running JSDoc. This problem mostly occurs with binary installations of perl Downloading The Most Recent Source Distribution of Perl and Building It on your own machine seems to solve this problem. Another action that can sometimes help in this situation (and does not require a new install of perl) is by changing the recursion limit for recursive regexes. You can do this by altering the value given to THE CONSTANT Recursion in JSDoc.pm (at line 124 at the time of write). Changing the value from 10 to a lower value, Such AS 6, can Sometimes take care of this issue. The main risk in taking this action is that thing Some Deeply-Nested CONSTRUCTS IN YOUR JavaScript code might not be processed by jsdoc. I want jsdoc to do x, but it doesn't! Well, That's actually not a question, it '

s more of a statement. However, it is stated quite frequently, so it's not totally out of place here. If you're interested in having a new feature added to JSDoc, you can register a Feature Request at the JSDoc Project Page. You may also want to consider sending information about your request to the JSDoc-user mailing list Is there a mailing list for JSDoc Okay, I admit that this is not actually a Frequently Asked Question;.? it's actually just an attempt to promote the JSDoc -user mailing list. I want to help out with JSDoc. Where should I start? First of all, help is very welcome! The most welcome kinds of help are context diffs that fix a bug in JSDoc, but pretty much anything that's an attempt At helping out is appreciated. Use the jsdoc-user mailing list.top

More Information A very complete and informative article (written by Rainer Eschen) on the use of JSDoc can be found at Webetiser. The article is based on JSDoc 1.5, but is still very relevant. I've been told that the article will be updated in the near future. As noted above, the definitive reference for writing Java docstrings can be found at the javadoc reference page. Please send comments, bugs, complaints, requests for additional information, and whatever else to the JSDoc mailing list.

TOP

转载请注明原文地址:https://www.9cbs.com/read-133502.html

New Post(0)