语法
¥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:
添加到每个事件的名称前面。通常,当链接到另一个 doclet 中的事件时,必须包含此命名空间。(@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 doclet 来记录事件的内容。相反,JSDoc Toolkit 2 使用 @event doclet 来标识在发生同名事件时可以触发的函数。
¥Note: JSDoc 3 uses @event doclets to document the content of an event. In contrast, JSDoc Toolkit 2 used @event doclets to identify a function that can be fired when an event of the same name occurs.
示例
¥Examples
以下示例显示如何记录 Hurl
类中名为 snowball
的事件。该事件包含一个具有单个属性的对象。
¥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.
*/