JavaScript Patterns 2.12 Writing API Docs
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的更多相关文章
- JavaScript Patterns 2.11 Writing Comments
Document all functions, their arguments and return values, and also any interesting or unusual algor ...
- JavaScript Patterns 2.1 Writing Maintainable Code
Revisiting the code after some time has passed requires: • Time to relearn and understand the proble ...
- JavaScript Patterns 5.4 Module Pattern
MYAPP.namespace('MYAPP.utilities.array'); MYAPP.utilities.array = (function () { // dependencies var ...
- 提高JavaScript 技能的12个概念
JavaScript 是一种复杂的语言.如果是你是高级或者初级 JavaScript 开发人员,了解它的基本概念非常重要.本文介绍 JavaScript 至关重要的12个概念,但绝对不是说 JavaS ...
- JavaScript强化教程——jQuery UI API 类别
---恢复内容开始--- 主要介绍:JavaScript强化教程—— jQuery UI API 类别 jQuery UI 在jQuery 内置的特效上添加了一些功能.jQuery UI 支持颜色动 ...
- 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 ...
- JavaScript Patterns 6.7 Borrowing Methods
Scenario You want to use just the methods you like, without inheriting all the other methods that yo ...
- JavaScript Patterns 6.6 Mix-ins
Loop through arguments and copy every property of every object passed to the function. And the resul ...
- JavaScript Patterns 6.5 Inheritance by Copying Properties
Shallow copy pattern function extend(parent, child) { var i; child = child || {}; for (i in parent) ...
随机推荐
- SQL Server技术问题之索引优缺点
索引是对数据库表中一列或多列的值进行排序的一种结构,使用索引可快速访问数据库表中的特定信息. 优点: 正确的索引会大大提高数据查询.对结果排序.分组的操作效率. 缺点: 1.存储空间,每个索引都要空间 ...
- 启动Mysql时发生的一个关于PID文件错误问题
今天启动mysql时出现了如下错误: [root@host1 /]# service mysql start Starting MySQL.. ERROR! The server quit wit ...
- Spring MVC的web.xml配置详解(转)
出处http://blog.csdn.net/u010796790 1.spring 框架解决字符串编码问题:过滤器 CharacterEncodingFilter(filter-name) 2.在w ...
- Ajax学习整理
什么是ajax?W3School中给ajax的定义是: 1.AJAX = 异步 JavaScript 和 XML. 2.AJAX 是一种用于创建快速动态网页的技术. 3.通过在后台与服务器进行少量数据 ...
- DBSet Class(EF基础系列11)
Method Name Return Type Description Add Added entity type Adds the given entity to the cont ...
- Android --- 斗地主 [牌桌实现源码]
1.主Activity <span style="font-size:18px;color:#3333ff;">package com.bison; import an ...
- Winform开发框架之统计图表的实现
在前面的一些随笔中,介绍了不少我的Winform框架的特性,上篇随笔<Winform开发框架之通用高级查询模块>对其中的通用高级模块进了一个整理说明,本篇继续介绍Winform开发框架重要 ...
- 如何弹出一定的大小的web窗体?
如何弹出一定的大小的web窗体? 摘自: http://blog.163.com/hweibin126@126/blog/static/17044246920108413348344/ 一.wind ...
- csharp:VerifyCode in winform or webform
winform: using System; using System.Collections.Generic; using System.ComponentModel; using System.D ...
- iis到w3wp的数据流及工作原理
HTTP.sys->IO线程-CLR线程池中的worker线程处理 IO线程只负责把请求交给Worker线程或者放入进程池级别的队列,然后又去HTTP.SYS的队列中处理其它的请求