gpt4 book ai didi

javascript - 如何在 JSDoc 中将参数标记为包含 DOM 节点?

转载 作者:IT王子 更新时间:2023-10-29 03:15:50 30 4
gpt4 key购买 nike

我想指出一个参数应该是一个 DOM 节点,但我似乎无法找到任何关于如何使用 JSDoc 来表明这一点的信息。我可以只使用 {Object},但这相当丑陋。我更愿意使用 {Node}{DOMNode} 之类的东西,但我找不到任何示例来指向那个方向。

那么,如何将参数标记为需要 DOM 节点?

最佳答案

来自 jsdoc.app对于 @type 注释:

A type expression can include the JSDoc namepath to a symbol (for example, myNamespace.MyClass); a built-in JavaScript type (for example, string); or a combination of these. You can use any Google Closure Compiler type expression, as well as several other formats that are specific to JSDoc.

[...]

Each type is specified by providing a type expression, using one of the formats described below. Where appropriate, JSDoc will automatically create links to the documentation for other symbols. For example, @type {MyClass} will link to the MyClass documentation if that symbol has been documented.

因此您可以链接到符号。 HTMLElement (以及像 HTMLImageElement 这样的继承对象)是符号。因此,如果您遵循规范,您应该被允许这样做:

@type {HTMLElement}

表示某物的类型是 HTMLElement(即 DOM 节点)。

我猜测为什么没有明确记录是因为 DOM 节点对象不是 JavaScript 内置的(例如 StringNumber)。它们由客户端浏览器添加,因此就 JS 语言规范而言,它们在技术上与您和我可以制作的任何其他符号一样(除了使用 native 浏览器代码实现)。

虽然我们还没有进入实际编译文档的阶段(那是一个单独的故事),这将确认 JSDoc 是否真正接受了上述内容,这就是我们在工作中解释和遵循这个特定概念的方式,我们的标准 IDE (IntelliJ) 接受它。

关于javascript - 如何在 JSDoc 中将参数标记为包含 DOM 节点?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21489044/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com