如何在 JSDoc 中记录事件处理程序?

发布于 2024-08-22 09:42:42 字数 347 浏览 4 评论 0原文

假设我有一个这样的类:

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

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

有没有办法向 JSDoc 指示 someFunction 不仅仅是一个应该直接调用的函数,而是一个事件处理程序?

我看到了 @event 标签,但如果我理解正确的话,这更多的是记录我的类中的一个函数,我认为该函数是一个事件(客户端代码也会注册,并且我的类将在需要时触发)而不是事件处理程序功能 ?

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 ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

惯饮孤独 2024-08-29 09:42:42

关键字是 @listens

用法示例:

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

推论是 @fires 用于引发事件的关键字。

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.

俯瞰星空 2024-08-29 09:42:42

不,没有办法记录事件处理程序。

因此,最好的方法是将其记录为普通函数,可能在其描述中用粗体文本或大写字母书写“事件处理程序”。

您可能已经知道了这一点,但以防万一:您可以通过简单地将文本包装到 html 标签 中以粗体书写。

这答案现已弃用,但它不允许我删除它。

No, there is no way to document an event handler.

So the best way is to document it as a normal function maybe writing in its description in bold text or upper case that is an "EVENT HANDLER".

You probably already now this, but just in case: you can write it in bold by simply wrapping the text into html tags <strong></strong>.

This answer is now deprecated but it does not let me delete it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文