Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to document an event handler in JSDoc?

Suppose I have a class like this:

function myClass(q) {
  this.someFunction = function(e) {
      console.log("Click event");
  };

  jQuery(q).click(this.someFunction);
}

Is there a way to indicate to JSDoc that someFunction is not just a function that should be invoked directly but rather is an event handler ?

I see the @event tag but if I understand correctly this is more to document a function in my class that I consider to be an event (something the client code would register too and that my class will fire when needed) and not an event handler function ?

like image 675
SBUJOLD Avatar asked Feb 19 '10 21:02

SBUJOLD


People also ask

How are event handlers registered in JavaScript?

You can register event handlers for either phase, bubbling or capturing, by using the function addEventListener(type, listener, useCapture) . If useCapture is set to false , the event handler is in the bubbling phase. Otherwise it's in the capture phase. The order of the phases of the event depends on the browser.

How do you write comments in JSDoc?

JSDoc comments should generally be placed immediately before the code being documented. Each comment must start with a /** sequence in order to be recognized by the JSDoc parser. Comments beginning with /* , /*** , or more than 3 stars will be ignored.

Which operator is used to attach an event handler to an event?

C# supports event handler assignment using: The += operator, which is also used in the common language runtime (CLR) event handling model.


1 Answers

The keyword is @listens

Usage example:

/**
 * Outputs the event that happened
 *
 * @param {MyEvent} e - The observable event.
 * @listens MyEvent
 */
function myEventLogger(e) {
    console.log(e);
}

The corollary is the @fires keyword for raising the event.

like image 162
Chris Marisic Avatar answered Sep 29 '22 18:09

Chris Marisic