简体   繁体   English

JSDoc 正确记录事件监听器

[英]JSDoc documenting event listeners properly

Ive been learning how to use JSDoc with my projects, I mostly understand how to use it with the exception of 1 or two things.我一直在学习如何在我的项目中使用 JSDoc,除了一两件事之外,我大多了解如何使用它。 One of these things being documenting event listeners.其中之一是记录事件侦听器。

Ive seen the documentation on the @listens, but the explanation/example they give is not making sense to me.我看过@listens 上的文档,但他们给出的解释/示例对我来说没有意义。 Heres a link to the page: https://jsdoc.app/tags-listens.html这是页面的链接: https://jsdoc.app/tags-listens.html

I was wondering if anyone has a better way of explaining it to me, or maybe show me an example of how you document a basic event listener.我想知道是否有人有更好的方法向我解释它,或者向我展示一个如何记录基本事件侦听器的示例。 (Ill provide one below) (我在下面提供一个)

document.getElementById('some_element').addEventListener('mousedown', function () {
  // Some code
});

Thanks谢谢

Extending on my comment above, I figure that the following would be an acceptable way to document that line of code, in which document is the namespace, followed by the event name mousedown :扩展我上面的评论,我认为以下是记录该代码行的可接受方式,其中document是命名空间,后跟事件名称mousedown

/**
 * Listen to mousedown event
 *
 * @type {HTMLElement} - the target of the event
 * @listens document#mousedown - the namespace and name of the event
 */

document.getElementById('some_element').addEventListener('mousedown', function () {
  // Some code
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM