我一直在学习如何在我的项目中使用 JSDoc,除了一两件事之外,我大多了解如何使用它。其中之一是记录事件监听器。
我看过@listens 上的文档,但他们给出的解释/示例对我来说没有意义。这是该页面的链接:https://jsdoc.app/tags-listens.html
我想知道是否有人有更好的方法向我解释它,或者向我展示一个如何记录基本事件监听器的示例。 (我在下面提供一个)
document.getElementById('some_element').addEventListener('mousedown', function () {
// Some code
});
谢谢
最佳答案
扩展我上面的评论,我认为以下是记录该代码行的可接受方式,其中 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
});
关于javascript - JSDoc 正确记录事件监听器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62576757/