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

在这个示例中,我们有一个名为“config”的命名空间。我们希望关于 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]
*/

:::