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. 叨叨PS那些活

    临睡前记得今天技术小结没写...就起来叨叨些使用Photoshop做网站的活吧. 一般网站的建站流程和人员配置是: 1 美工,创建页面的psd图 2 前端工程师,根据psd图,切出html页面 3 后 ...

  2. .Net魔法堂:AssemblyInfo.cs文件详解

    一.前言 .net工程的Properties文件夹下自动生成一个名为AssemblyInfo.cs的文件,一般情况下我们很少直接改动该文件.但我们实际上通过另一个形式操作该文件.那就是通过在鼠标右键点 ...

  3. Scrum 项目5.0--软件工程

    1.燃尽图: 2.每日立会更新任务板上任务完成情况.燃尽图的实际线,分析项目进度是否在正轨.    每天的例会结束后的都为任务板拍照并发布到博客上     团队贡献分: 蔡舜 : 21 卢晓洵 : 1 ...

  4. 用Qt写软件系列二:QCookieViewer(浏览器Cookie查看器)

    预备 继上篇<浏览器缓存查看器QCacheViewer>之后,本篇开始QCookieViewer的编写.Cookie技术作为网站收集用户隐私信息.分析用户偏好的一种手段,广泛应用于各大网站 ...

  5. Ubuntu13.04配置:Vim+Syntastic+Vundle+YouCompleteMe

    序言 使用Ubuntu和vim已经有一段时间了,对于Vim下的插件应用,我总是抱着一股狂热的态度.这次,又在网上闲逛着,发现了一个个人博客提到了Vim代码补全这回事,并提到了YouCompleteMe ...

  6. 环信SDK与Apple Watch的结合(3)

    第3章主要介绍怎样在Watch App的页面上显示iPhone程序里的数据.主要操作的是“EMWatchOCDemo WatchKit Extension”这个文件夹,附源码EMWatchOCDemo ...

  7. Winform屏幕截图保存C#代码

    代码如下: using System.Runtime.InteropServices; using System.Drawing.Imaging; [System.Runtime.InteropSer ...

  8. 数据库表被锁表,select会等待。

    SELECT * FROM dbo.Table_1 WITH(NOLOCK) 这样就可以不用等待,但数据读的是被锁之前的数据,表被锁了,肯定会有对表的update,delete操作. 如果对数据的准确 ...

  9. PDT已有很大改进

    受够了NB的低性能文件扫描,也许是时候放弃Netbeans迎接PDT了.

  10. Python调用C的SDK出现返回值不符合预期以及Segmentation fault

    1.sdk返回值不是int型 1.1 登录函数调用 def login(ip, port, username, password, device_info, error_code):"&qu ...