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 ?
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.
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.
C# supports event handler assignment using: The += operator, which is also used in the common language runtime (CLR) event handling model.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With