当前位置: 首页 > 文档资料 > JSDoc 中文文档 >

@listens

优质
小牛编辑
134浏览
2023-12-01

描述:列出一个标识的监听事件。

语法

@listens <eventName>

概述

@listens 标签指示一个标识监听指定的事件。使用@event 标签来记录事件的内容。

例子

下面的示例演示了如何记录名为module:hurler~event:snowball的事件,还有一个方法命名为module:playground/monitor.reportThrowage来监听事件。

例如,描述一个事件和它的监听器:

define('hurler', [], function () {
    /**
     * Event reporting that a snowball has been hurled.
     *
     * @event module:hurler~snowball
     * @property {number} velocity - The snowball's velocity, in meters per second.
     */

    /**
     * Snowball-hurling module.
     *
     * @module hurler
     */
    var exports = {
        /**
         * Attack an innocent (or guilty) person with a snowball.
         *
         * @method
         * @fires module:hurler~snowball
         */
        attack: function () {
            this.emit('snowball', { velocity: 10 });
        }
    };

    return exports;
});

define('playground/monitor', [], function () {
    /**
     * Keeps an eye out for snowball-throwers.
     *
     * @module playground/monitor
     */
    var exports = {
        /**
         * Report the throwing of a snowball.
         *
         * @method
         * @param {module:hurler~event:snowball} e - A snowball event.
         * @listens module:hurler~event:snowball
         */
        reportThrowage: function (e) {
            this.log('snowball thrown: velocity ' + e.velocity);
        }
    };

    return exports;
});