加载中...

@listens


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

语法

@listens <eventName>

概述

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

例子

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

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

  1. define('hurler', [], function () {
  2. /**
  3. * Event reporting that a snowball has been hurled.
  4. *
  5. * @event module:hurler~snowball
  6. * @property {number} velocity - The snowball's velocity, in meters per second.
  7. */
  8.  
  9. /**
  10. * Snowball-hurling module.
  11. *
  12. * @module hurler
  13. */
  14. var exports = {
  15. /**
  16. * Attack an innocent (or guilty) person with a snowball.
  17. *
  18. * @method
  19. * @fires module:hurler~snowball
  20. */
  21. attack: function () {
  22. this.emit('snowball', { velocity: 10 });
  23. }
  24. };
  25.  
  26. return exports;
  27. });
  28.  
  29. define('playground/monitor', [], function () {
  30. /**
  31. * Keeps an eye out for snowball-throwers.
  32. *
  33. * @module playground/monitor
  34. */
  35. var exports = {
  36. /**
  37. * Report the throwing of a snowball.
  38. *
  39. * @method
  40. * @param {module:hurler~event:snowball} e - A snowball event.
  41. * @listens module:hurler~event:snowball
  42. */
  43. reportThrowage: function (e) {
  44. this.log('snowball thrown: velocity ' + e.velocity);
  45. }
  46. };
  47.  
  48. return exports;
  49. });


还没有评论.