JSDoc 中文网

Synonyms

概述

¥Overview

@property 标签是一种轻松记录类、命名空间或其他对象的静态属性列表的方法。

¥The @property tag is a way to easily document a list of static properties of a class, namespace or other object.

通常,JSDoc 模板会创建一个全新的页面来显示有关嵌套命名空间层次结构的每个级别的信息。有时,你真正想要的只是在同一页面上列出所有属性,包括嵌套属性。

¥Normally JSDoc templates would create an entire new page to display information about each level of a nested namespace hierarchy. Sometimes what you really want is to just list all the properties, including nested properties, all together on the same page.

请注意,属性标签必须在文档注释中用于它们所属的属性,例如命名空间或类。该标签适用于静态属性的简单集合,它不允许你为每个属性提供 @examples 或类似的复杂信息,而仅提供类型、名称和描述。

¥Note that property tags must be used in doc comments for the thing that they are properties of, a namespace or a class for example. This tag is intended for simple collections of static properties, it does not allow you to provide @examples or similar complex information for each property, just the type, name and description.

示例

¥Examples

在此示例中,我们有一个名为 "配置。" 的命名空间。我们希望有关 defaults 属性的所有信息(包括其嵌套值)与 config 文档显示在同一页面上。

¥In this example we have a namespace named "config." We want all the information about the defaults property, including its nested values, to appear on the same page with the documentation for config.

具有默认值和嵌套默认属性的命名空间
/**

 * @namespace

 * @property {object}  defaults               - The default values for parties.

 * @property {number}  defaults.players       - The default number of players.

 * @property {string}  defaults.level         - The default level for the party.

 * @property {object}  defaults.treasure      - The default treasure.

 * @property {number}  defaults.treasure.gold - How much gold the party starts with.
 */
var config = {
    defaults: {
        players: 1,
        level:   'beginner',
        treasure: {
            gold: 0
        }
    }
};

以下示例显示如何指示属性是可选的。

¥The following example shows how to indicate that a property is optional.

具有必需和可选属性的类型定义
/**

* User type definition

* @typedef {Object} User

* @property {string} email

* @property {string} [nickName]
*/