Free and open source tools for doc generation:

the JSDoc Toolkit (http://code.google.com/p/jsdoc-toolkit/)

and YUIDoc (http://yuilibrary.com/projects/yuidoc).

Process of generating API documentation

• Writing specially formatted code blocks

• Running a tool to parse the code and the comments

• Publishing the results of the tool, which are most often HTML pages

/**

* Reverse a string

*

* @param {String} input String to reverse

* @return {String} The reversed string

*/

var reverse = function (input) {
// ...
return output;
}; 

The contents of app.js starts like this:

/**

* My JavaScript application

*

* @module myapp

*/

Then you define a blank object to use as a namespace:

var MYAPP = {};

And then you define an object math_stuff that has two methods: sum() and multi():

/**

* A math utility

* @namespace MYAPP

* @class math_stuff

*/

MYAPP.math_stuff = {

    /**

    * Sums two numbers

    *

    * @method sum

    * @param {Number} a First number

    * @param {Number} b The second number

    * @return {Number} The sum of the two inputs

    */

    sum: function (a, b) {
return a + b;
}, /** * Multiplies two numbers * * @method multi * @param {Number} a First number * @param {Number} b The second number * @return {Number} The two inputs multiplied */
multi: function (a, b) {
return a * b;
}
}; 

@namespace

The global reference that contains your object.

@class

A misnomer (no classes in JavaScript) that is used to mean either an object or a constructor function.

@method

Defines a method in an object and specifies the method name.

@param

Lists the arguments that a function takes. The types of the parameters are in curly braces, followed by the parameter name and its description.

@return

Like @param, only it describes the value returned by the method and has no name.

• @constructor hints that this “class” is actually a constructor function

• @property and @type describe properties of an object

/**

* Constructs Person objects

* @class Person

* @constructor

* @namespace MYAPP

* @param {String} first First name

* @param {String} last Last name

*/

MYAPP.Person = function (first, last) {

    /**

    * Name of the person

    * @property first_name

    * @type String

    */
this.first_name = first; /** * Last (family) name of the person * @property last_name * @type String */
this.last_name = last;
}; /** * Returns the name of the person object * * @method getName * @return {String} The name of the person */ MYAPP.Person.prototype.getName = function () {
return this.first_name + ' ' + this.last_name;
};

YUIDoc Example

JavaScript Patterns 2.12 Writing API Docs的更多相关文章

  1. JavaScript Patterns 2.11 Writing Comments

    Document all functions, their arguments and return values, and also any interesting or unusual algor ...

  2. JavaScript Patterns 2.1 Writing Maintainable Code

    Revisiting the code after some time has passed requires: • Time to relearn and understand the proble ...

  3. JavaScript Patterns 5.4 Module Pattern

    MYAPP.namespace('MYAPP.utilities.array'); MYAPP.utilities.array = (function () { // dependencies var ...

  4. 提高JavaScript 技能的12个概念

    JavaScript 是一种复杂的语言.如果是你是高级或者初级 JavaScript 开发人员,了解它的基本概念非常重要.本文介绍 JavaScript 至关重要的12个概念,但绝对不是说 JavaS ...

  5. JavaScript强化教程——jQuery UI API 类别

    ---恢复内容开始--- 主要介绍:JavaScript强化教程​—— jQuery UI API 类别 jQuery UI 在jQuery 内置的特效上添加了一些功能.jQuery UI 支持颜色动 ...

  6. JavaScript Patterns 7.1 Singleton

    7.1 Singleton The idea of the singleton pattern is to have only one instance of a specific class. Th ...

  7. JavaScript Patterns 6.7 Borrowing Methods

    Scenario You want to use just the methods you like, without inheriting all the other methods that yo ...

  8. JavaScript Patterns 6.6 Mix-ins

    Loop through arguments and copy every property of every object passed to the function. And the resul ...

  9. JavaScript Patterns 6.5 Inheritance by Copying Properties

    Shallow copy pattern function extend(parent, child) { var i; child = child || {}; for (i in parent) ...

随机推荐

  1. 我也想聊聊 OAuth 2.0 —— 基本概念

    这是一篇待在草稿箱半年之久的文章 连我自己都不知道我的草稿箱有多少未发布的文章了.这应该是我在上一家公司未解散之前写的,记得当时是要做一个开发者中心,很不幸. 今天,打开草稿箱有种莫名的伤感,看到这个 ...

  2. js-计时事件

    JavaScript 一个设定的时间间隔之后来执行代码,称之为计时事件. 主要通过两个方法来实现:     1.setInterval() - 间隔指定的毫秒数不停地执行指定的代码.     2.se ...

  3. 6/19 sprint3 看板和燃尽图的更新

  4. SQL Server存储过程复习(一)

    --存储过程学习篇 --.简单存储过程不带参数的学习 IF OBJECT_ID('Orders_GetAllOrders','P') IS NOT NULL DROP PROCEDURE Orders ...

  5. IDM主机上安装融合应用程序配置框架

    IDM主机上安装融合应用程序配置框架   安装Oracle融合应用程序>设置>身份和访问管理节点安装融合应用程序配置框架 由于我们使用Oracle VirtualBox虚拟机这一次,我们在 ...

  6. ASP.NET 使用AJAX让GridView的数据行显示提示框(ToolTip)

    介绍ASP.NET AJAX可以使你的web应用程序具有更丰富的功能和更多的用户响应. 本文中,我将演示如何通过ASP.NET AJAX的帮助,给像GridView这样的数据绑定控件的数据行增加pop ...

  7. Winform窗体实现简单的二维码生成和保存

    二维码的生成需要用到二维码生成的类库,ThoughtWorks.QRCode.dll 步骤: 第一步:下载二维码生成类库,ThoughtWorks.QRCode.dll 第二步:新建winform项目 ...

  8. KM算法

    链接: http://blog.csdn.net/lvshubao1314/article/details/41702291 

  9. tomcat filewatchdog but has failed to stop it原因以及解决方法

    停止tomcat,有些时候会报The web application [/XXX] appears to have started a thread named [FileWatchdog] but ...

  10. JS之跨域

    今天学了跨域,迫不及待想跟大家分享!不妥之处希望大家指正. 首先来明确一下"跨域"这个概念. 跨域指的是,到外域去取数据.那什么是"外域"呢?我们先来了解同域. ...