语法
🌐 Syntax
@event <className>#[event:]<eventName>
概述
🌐 Overview
@event 标签允许你记录可以触发的事件。一个典型的事件由一个具有定义属性集合的对象表示。
🌐 The @event tag allows you to document an event that can be fired. A typical event is represented by an object with a defined set of properties.
一旦你使用 @event 标签定义了特定类型的事件,你可以使用 @fires 标签来表示一个方法可以触发该事件。你还可以使用 @listens 标签来表示某个符号监听该事件。
🌐 Once you have used the @event tag to define a specific type of event, you can use the @fires tag to indicate that a method can fire that event. You can also use the @listens tag to indicate that a symbol listens for the event.
JSDoc 会自动将命名空间 event: 添加到每个事件的名称前。一般来说,当你在另一个文档元素中链接该事件时,你必须包含此命名空间。(@fires 标签是一个显著的例外;它允许你省略命名空间。)
🌐 JSDoc automatically prepends the namespace event: to each event's name. In general, you must
include this namespace when you link to the event in another doclet. (The @fires tag is a notable
exception; it allows you to omit the namespace.)
注意:JSDoc 3 使用 @event 文档标记来记录事件的内容。相比之下,JSDoc Toolkit 2 使用 @event 文档标记来标识在发生同名事件时可以被触发的函数。
示例
🌐 Examples
以下示例展示了如何在名为 snowball 的 Hurl 类中记录事件。该事件包含一个具有单个属性的对象。
🌐 The following examples show how to document an event in the Hurl class called snowball. The
event contains an object with a single property.
/**
* Throw a snowball.
*
* @fires Hurl#snowball
*/
Hurl.prototype.snowball = function() {
/**
* Snowball event.
*
* @event Hurl#snowball
* @type {object}
* @property {boolean} isPacked - Indicates whether the snowball is tightly packed.
*/
this.emit('snowball', {
isPacked: this._snowball.isPacked
});
};
/**
* Throw a snowball.
*
* @fires Hurl#snowball
*/
Hurl.prototype.snowball = function() {
// ...
};
/**
* Snowball event.
*
* @event Hurl#snowball
* @type {object}
* @property {boolean} isPacked - Indicates whether the snowball is tightly packed.
*/