ScriptDoc 2.0 参考手册

ScriptDoc 2.0 参考手册

出处:https://wiki.appcelerator.org/display/tis/ScriptDoc+%28SDOC%29+2.0+Specification

 

ScriptDoc (SDOC) 2.0 Specification

Added by Kevin Lindsey, last edited by Ingo Muschenetz on Sep 22, 2011 (view change)


1 Introduction
2 Reference
2.1 @alias
2.2 @author
2.3 @classDescription
2.4 @constructor
2.5 @deprecated
2.6 @example
2.7 @exception
2.8 @id
2.9 @inherits
2.10 @internal
2.11 @memberOf
2.12 @method
2.13 @namespace
2.14 @param
2.15 @private
2.16 @projectDescription
2.17 @property
2.18 @return
2.19 @see
2.20 @since
2.21 @type
2.22 @version


Introduction

This reference page provides comprehensive documentation for all ScriptDoc tags, in alphabetical order.

Several tags have "synonyms" where you can use two differently named tags to document the same thing. You can use a synonym by using the exact same syntax as the original tag, but just substituting the tag name.

The section for each tag includes the following information:

    Short description of the tag
    Syntax
    What the tag applies to
    Longer explanation of the tag
    Example (Some tags have multiple examples)

 

Reference

The following tags are valid for code documentation:

@alias

ID for a class or function.

Applies to: Any

Syntax

@alias fooBar

Description

Use the @alias tag to ID a class or function if you have used a "shorthand" way to code the full name for that class or function.

Example

This example shows the @alias tag used to id a function called fooBar in the FOO.Lib namespace.

FOO.Lib.update(FOO.Lib) {
     
/**
  * Returns a function that will return a number one greater than the previous returned value, starting at n.
  * @alias fooBar
  * @alias FOO.Lib.fooBar
  * @param {Object} n    Number to start with. Default is 1.
  * @return {Function) Returns a function that will return a number one greater than the previous returned value.
  */
    fooBar: function (n /* = 1 */ ) {
        if (arguments.length === 0) {
            n = 1;
        }
        return function () {
            return n++;
        };
    },

@author

Author of a JavaScript file or function.

Applies to: Any

Syntax

@author Author-name [email]

Description

Use @author to credit the author of a JavaScript file or function.

Example

This example shows the @author tag used with the @fileoverview and @version tags to provide header information for a JavaScript file.

/**
* @projectDescription   Joe Smith's wonderful JavaScript library.
*
* @author   Joe Smith [email protected]
* @version  0.1
*/

@classDescription

Description of the class.

Applies to: Function

Syntax

@classDescription Description

Description

Use the @classDescription tag to give a short description of the class (if applicable).

Example

This example shows a sample documentation block for a basic Shape class.

/**
* Create a new instance of Shape.
*
* @classDescription This class creates a new Shape.
* @return {Shape}   Returns a new Shape.
* @type {Object}
* @constructor 
*/
function Shape() {
}

@constructor

Shows that a function is a constructor for a class.

Applies to: Function

Syntax

@constructor

Description

Use the @constructor tag to signify that a function is a constructor if you are coding in an object-oriented programming style.

Example

This example shows a sample documentation block for a basic Shape class.

/**
* Create a new instance of Shape.
*
* @classDescription This class creates a new Shape.
* @return {Object}  Returns a new Shape object.
* @constructor 
*/
function Shape() {
}

@deprecated

Signifies that a function or a property has been deprecated.

Applies to: Function or property.

Syntax

@deprecated

Description

Use the @deprecated tag to show that a function or a property has been deprecated and should not be used.

Example

This example shows a @deprecated tag added to a documentation block for a function.

/**
* This function gets a foo by name.
* @param {Object}   fooName Name of the foo to retrieve.
* @return {Object}  Returns a new foo.
* @deprecated
*/

@example

Gives an example for the function being documented.

Applies to: Any (except @projectDescription)

Syntax

@example Example-code

Description

Use the @example tag when you want to show an example of how to use the code that you are documenting. Any whitespace you add will be included when the tag is parsed. You can also include basic HTML to make your example more readable.

Example

This example shows a documentation block for a "move" function that takes the arguments "layerID" and "direction" and includes an @example tag with code example. Use HTML tags to format your descriptions. Use the

{code}{code}

tag set to format the example as code. (This example uses the @remarks tag to give more information about the function.)

/**
* This function moves a layer in the specified direction.
* @param {String}   layerID The ID for the layer to be moved.
* @param {String}   direction   The direction for the layer to be moved.
* @param {Number}   number  Number of pixels to move the layer.
* @remarks The direction argument can be "right" , "left" , "up" , or "down" .
*          You cannot move the layer beyond the boundaries of the browser window.
* @example  Using the move function
*           This example uses the move function to move myLayer to the right by 50 pixels.
*           move(myLayer, right, 50)
* /
function move(layerID, direction, number)

@exception

Specifies the type of exception thrown by a function.

Applies to: Function

Syntax

@exception {Exception} Exception-description

Description

Use the @exception tag to specify any exceptions thrown by a function. You can specify multiple exceptions in a documentation block.

Example

This example shows a function that throws two exceptions--a "MemoryException" and a "GeneralShapeException".

/**
* This function creates a new Shape object.
*
* @exception    {MemoryException}   Throws a memory exception if out of memory.
* @exception    {GeneralShapeException} Throws a general shape exception if the object is not a shape.
* @return   {Object}    Returns a new shape object.
*/

@id

Unique identifier for a function or property.

Applies to: All

Syntax

@id identifierName

Description

Use @id to link a function or property to its documentation in an external @sdoc file. Add the @id tag both inline right above a function and to the documentation block in the .sdoc file to create the link.

Example

This example shows an inline @id tag for the function foo.

/** @id */
function foo() {
   alert( "Foo!" );
}

@inherits

Indicates that one item "inherits" from another

Applies to: Function

Syntax

@inherits _functionNameA_
  @inherits _functionNameB_

or

@inherits _functionNameA_, _functionNameB_

Description

Use @inherits to indicate that one "class" subclasses another in object-oriented JavaScript.

Example

This example shows that bar inherits from foo.

function foo() {
}
 
/** @inherits foo */
function bar() {
}

@internal

Specifies that a function or property should not be made visible by Content Assist.

Applies to: Function, Property

Syntax

@internal

Description

Specifies that a function or property should not be made visible by Content Assist.

Example

This example shows an @internal tag.

/**
* @internal
*/

@memberOf

Signifies that a function is a member of the specified class.

Applies to: Function, Property.

Syntax

@memberOf Class

Description

Use the @memberOf tag to signify that a function is a member of the specified class.

Example

This example shows that the getFoo function is a member of the fooBar class.

/**
* @memberOf fooBar
*/
function getFoo(){
}

@method

Signifies that a function is a method of a class, if applicable.

Applies to: Function

Syntax

@method

Description

Use the @method tag to signify a method of a class if you are coding in an object-oriented programming style.

Example

This example shows a @method tag.

/**
* @method
*/

@namespace

Creates the namespace prefix for a library file.

Applies to: File

Syntax

@namespace namespaceName

Description

Creates the link between the namespace of a library file and an external .sdoc file.

Example

This example shows how to use the @namespace tag to link the namespace of a library to an .sdoc file.

The excerpt below would go at both the top of the library file that contains the "ajax" namespace for the "snazzyLib" library and the corresponding "ajax.sdoc" file that contains the documentation for the "ajax" namespace in snazzyLib:

/**
  * @namespace snazzyLib.ajax
  */

@param

Use @param to tag each parameter for a function.

Applies to: Function

Syntax

@param {Type[, Type, _.]} [Parameter ] Parameter-Description

Description

Gives information about a parameter for a function. Specify the data type between the curly braces. If the parameter is optional, add '[]' around the parameter name.

Examples

Standard example

The following example shows a parameter for a function that takes a String named myDog.

/**
  * @param {String} myDog The name of the dog.
  */

Optional parameter example

The following example shows an optional parameter that can be either a String or a Date.

/**
  * @param {String, Date} [myDate] Specifies the date, if applicable.
  */

Multiple objects example

The following example shows a parameter that can be one or more Strings.

/**
  * @param {String} ... Takes one or more dog parameters.
  */

@private

Signifies that a class or a function is private.

Applies to: Function, Property

Syntax

@private

Description

Use the @private tag to signify that a class or function is private. The ScriptDoc output will not include private classes or functions unless you run ScriptDoc with the --private commmand line argument.

Example

This example shows a private function that returns a foo.

/**
  * This function creates a new foo.
  * @private
  * @return {Object} Returns a foo.
  */

@projectDescription

Gives a description of a JavaScript file.

Applies to: File.

Syntax

@projectDescription Description

Description

Use the @projectDescription tag as the first tag in the first documentation block for a JavaScript file. The @projectDescription tag signifies that the entire documentation block is part of a project description.

Example

This example shows the @projectDescription tag used with the @author and @version tags to provide header information for a JavaScript file.

/**
  * @projectDescription  This library contains a lot of classes and functions.
  *
  * @author  Joe Smith [email protected]
  * @version     0.1
  */

@property

Indicates that a member is a property of a class instance

Applies to: File.

Syntax

@property {Type [, Type, _.]}

Description

Use the @property tag to indicate that the following member is a property (as opposed to a method) of a class instance.

Example

This example shows the @property tag being used to define a "myProperty" property on the MyClass class. The property contains a description and will be treated as a String.

/**
  * This is a property of class MyClass
  *
  * @alias MyClass.myProperty
  * @property {String}
  */

@return

Specifies information about the return value(s) of a function.

Applies to: Function

Syntax

@return {Type [, Type, _.]} Returns-Description

Description

@return gives a description for the return value of a function.

Example

This example shows a return value for a function that returns a new foo object.

/**
  * @return {Object} Returns a new foo object.  
  */

@see

Links to another related class or function.

Applies to: Any

Syntax

@see Class | #Function | Class#Function

Description

Use the @see tag to add a link to another class, a function within the current class, or a function in another class.

Examples

Function example

This example shows a link to a function named "foo" in the same class as the one being documented.

/**
  * @see #foo
  */

Class example

This example shows a link to a class named "fooBar".

/**
  * @see fooBar
  */

Function in another class example

This example shows a link to a function named "foo" in another class named "fooBar".

/**
  * @see fooBar#foo
  */

@since

Specifies since which version the library, function, or property became valid.

Applies to: File, Function, Property

Syntax

@since Version-number

Description

Specifies since which version the library, function, or property became valid.

Example

This example shows a @since tag, used in conjunction with @projectDescription, @author, and @version tags. A documentation block like this would go at the top of a JavaScript file.

/**
  * @projectDescription  This library contains a lot of classes and functions.
  *
  * @author  Joe Smith [email protected]
  * @version     1.1
  * @since   1.0
  */

@type

Specifies what data type a property is.

Applies to Property

Syntax

@type {Type}

Description

Specifies what data type a property is.

Example

This example uses the @return tag with the @type tag to show the return type for a function that creates a new foo.

/**
  * This property describes what type of shape an object is.
  * @type {Object} This property describes what type of shape an object is.
  */

@version

Specifies the version number of the JavaScript file or class.

Applies to: Any

Syntax

@version Version-Number

Description

Specifies the version number of the JavaScript file or class.

Example

This example shows the @version tag used with the @projectDescription and @author tags to provide header information for a JavaScript file.

/**
  * @projectDescription A description of the file ahead
  *
  * @author  Joe Smith [email protected]
  * @version     0.1
  */
 
 
 

scriptDoc 2.0 参考
简介:
这里介绍scriptDoc2.0的标签,一些标签会有一些同义词,再用的时候可以根据个人喜好选择使用。
每一个标记包括以下的信息:
概述
句法(Syntax)
这个标记的作用
详细解释
列子
@alias
概述 :类 Class 或者函数 function的ID
句法(Syntax):@alias fooBar
这个标记的作用 : 标识一个类或者函数,可以作为类或者函数的简称
例子:
/**
* Returns a function that will return a number one greater than the previous returned value, starting at n.
* @alias fooBar
* @alias FOO.Lib.fooBar
* @param {Object} n Number to start with. Default is 1.
* @return {Function) Returns a function that will return a number one greater than the previous returned value.
*/
fooBar: function (n/* = 1 */) {
if (arguments.length === 0) {
n = 1;
}
return function () {
return n++;
};
},
@author
概述 :显示作者信息
句法(Syntax):@author Author-name [email]
这个标记的作用 : 显示作者信息
例子:
/**
* @projectDescription Joe Smith's wonderful JavaScript library.
*
* @author Joe Smith [email protected]
* @version 0.1
*/
@classDescription
概述 :对class的描述
句法(Syntax):@classDescription Description
这个标记的作用 : 概述类的信息(在合适的情况下)
例子:
这个例子给出了一个基本的Shape类的doc
/**
* Create a new instance of Shape.
*
* @classDescription This class creates a new Shape.
* @return {Shape} Returns a new Shape.
* @type {Object}
* @constructor
*/
function Shape() {
}
@constructor
概述 :显示这个函数作为构造函数(constructor)
用于(Applies to): function
句法(Syntax):@constructor
这个标记的作用 : 在面向对象编程的时候,表示一个function作为构造函数存在
例子:可以用上面同样的例子举例 @classDescription
/**
* Create a new instance of Shape.
*
* @classDescription This class creates a new Shape.
* @return {Object} Returns a new Shape object.
* @constructor
*/
function Shape() {
}
@deprecated
概述 :说明一个函数或者属性被弃用
用于(Applies to): function 或者 属性(property)
句法(Syntax):@deprecated
这个标记的作用 : 用来说明某一个函数或者属性被弃用,通常在升级和重构的时候使用
例子:
/**
* This function gets a foo by name.
* @param {Object} fooName Name of the foo to retrieve.
* @return {Object} Returns a new foo.
* @deprecated
*/
@example
概述 :给出例子
句法(Syntax):@example Example-code
这个标记的作用 : 为已经添加注释的代码书写使用例子,可以添加空格和html标记
例子:这个例子说明了参数中layerID以及direction的用法,并且使用了@example给出了使用例子。如果使用
HTML的标记来格式化描述,使用{code}{code}格式化。
例子中使用了@remark标记给出了更多的描述
/**
* This function moves a layer in the specified direction.
* @param {String} layerID The ID for the layer to be moved.
* @param {String} direction The direction for the layer to be moved.
* @param {Number} number Number of pixels to move the layer.
* @remarks The direction argument can be "right", "left", "up", or "down".
* You cannot move the layer beyond the boundaries of the browser window.
* @example Using the move function
* This example uses the move function to move myLayer to the right by 50 pixels.
* move(myLayer, right, 50)
* /
function move(layerID, direction, number)
@exception
概述 :描述函数的exception
用于(Applies to): function
句法(Syntax):@exception {Exception} Exception-description
这个标记的作用 : 用来说明函数产生的任何的exception,可以在一个块中描述多个exception
例子:
这个例子中抛出了MemoryException 和一个 GeneralShapeException
/**
* This function creates a new Shape object.
*
* @exception {MemoryException} Throws a memory exception if out of memory.
* @exception {GeneralShapeException} Throws a general shape exception if the object is not a shape.
* @return {Object} Returns a new shape object.
*/
@id
概述 :标识一个函数或者属性
句法(Syntax):@id identifierName
这个标记的作用 : 用来将代码和外部的@soc file链接起来,需要同时在代码块和文档中加入此标识
例子:
在代码中可以使用如下的内联注释(inline @id)
/** @id */
function foo() {
alert("Foo!");
}
@inherits
概述 :表示一个函数继承自其他函数
用于 :function
句法(Syntax):@inherits _functionNameA_
@inherits _functionNameB_
或者
@inherits _functionNameA_, _functionNameB_
这个标记的作用 : 在javascript的面向对象编程中,标识其父类
例子:
下面的例子标识了bar继承自foo
function foo() {
}
/** @inherits foo */
function bar() {
}
@internal
概述 :标识一个函数或者属性不能够被Content Assist使用
用于 :function 或者 属性(Property)
句法(Syntax):@internal
这个标记的作用 : 要注意这个概念和“内部”或者“私有”的区别,这个标识只是不让Content Assist发现它
例子:
/**
* @internal
*/
@memberOf
概述 :表示函数或者属性是另一个class的成员函数或者属性
用于 :function 或者 属性(Property)
句法(Syntax):@memberOf Class
这个标记的作用 : 这个表示函数或者属性是成员函数或者属性,注意和@internal的区别
例子:
/**
* @memberOf fooBar
*/
function getFoo(){
}
@method
概述 :表示一个函数是被其他类使用的方法
用于 :function
句法(Syntax):@method
这个标记的作用 : 表示一个函数是被其他类使用的方法,和@memberOf相比,@method更侧重于通用的工具方法
例子:
/**
* @method
*/
@namespace
概述 :描述一个库文件(library file)的命名空间
用于 :file
句法(Syntax):@namespace namespaceName
这个标记的作用 : 可以通过@namespace为当前库文件和外部注释文档(external .sdoc file)建立链接
例子:下面的例子展示了一个通过@namespace注释的例子,这个注释同时出现在库文件和外部注释文档的头部
/**
* @namespace snazzyLib.ajax
*/
@param
概述 :描述参数信息
用于 :function
句法(Syntax):@param {Type[, Type, _.]} [Parameter] Parameter-Description
这个标记的作用 : 给出每一个参数的信息,在大括号中描述数据类型,如果参数是可选的,使用[]
例子:
一个标准的例子:
/**
* @param {String} myDog The name of the dog.
*/
可选参数的例子:
/**
* @param {String, Date} [myDate] Specifies the date, if applicable.
*/
下面的例子展示了一个参数可以是一个或多个String
/**
* @param {String} ... Takes one or more dog parameters.
*/

@private
概述 :表示一个类或者函数是私有的
用于 :function 或者属性
句法(Syntax):@private
这个标记的作用 : 使用@private标记标识一个类或者函数是私有的。ScriptDoc在输出的时候不会
包含私有的类或者函数除非运行ScriptDoc的时候使用--private命令。
例子:
/**
* This function creates a new foo.
* @private
* @return {Object} Returns a foo.
*/
@projectDescription
概述 :对一个javascript文件进行描述
用于 :file
句法(Syntax):@projectDescription Description
这个标记的作用 : 在一个javascript file中使用其作为第一个标记,这个标记表示整个文档属于一个project的一部分
例子:
这个例子给出了@projectDescription 以及@author @version
/**
* @projectDescription This library contains a lot of classes and functions.
*
* @author Joe Smith [email protected]
* @version 0.1
*/
@property
概述 :表示一个成员是一个类的实例的属性
用于 :file
句法(Syntax):@property {Type[, Type, _.]}
这个标记的作用 : 表示下述的成员是一个类的实例的属性
例子:
这个例子描述了myProperty这个String对象是MyClass的属性
/**
* This is a property of class MyClass
*
* @alias MyClass.myProperty
* @property {String}
*/
@return
概述 :描述函数的返回值
用于 :function
句法(Syntax):@return {Type[, Type, _.]} Returns-Description
这个标记的作用 : 描述函数的返回值
例子:
/**
* @return {Object} Returns a new foo object.
*/
@see
概述 :注释参照另一个相似的类或者函数
用于 :
句法(Syntax):@see Class|#Function|Class#Fuction
这个标记的作用 :注释参照另一个相似的类或者函数,可以是在同一个类中的函数,也可以是不同的类
例子:
同一个函数关联
/**
* @see #foo
*/
也可以同一个类关联
/**
* @see fooBar
*/
或者同一个类中的函数关联
/**
* @see fooBar
*/
@since
概述 :描述从哪一个版本开始起这个库、function、或者属性变得可用的
用于 :file、function、property
句法(Syntax):@since Version-number
这个标记的作用 : 描述从哪一个版本开始起这个库、function、或者属性变得可用的
例子:
这个例子结合了@projectDescription, @author, @version, @sinse,这样的注释块放到文档的最上方
/**
* @projectDescription This library contains a lot of classes and functions.
*
* @author Joe Smith [email protected]
* @version 1.1
* @since 1.0
*/
@type
概述 :描述一个属性是什么类型
用于 :属性
句法(Syntax):@type {Type}
这个标记的作用 : 描述一个属性是什么类型
例子:
/**
* This property describes what type of shape an object is.
* @type {Object} This property describes what type of shape an object is.
*/
@version
概述 :描述一个javascript文档或者一个类的版本号
句法(Syntax):@version Version-Number
这个标记的作用 : 描述一个javascript文档或者一个类的版本号
例子:
/**
* @projectDescription A description of the file ahead
*
* @author Joe Smith [email protected]
* @version 0.1
*/

你可能感兴趣的:(script)