gpt4 book ai didi

javascript - Eclipse/JSDT 中的类型声明/推断

转载 作者:行者123 更新时间:2023-12-01 13:57:32 29 4
gpt4 key购买 nike

我想在 Eclipse/JSDT 中指定实例变量的类型,如下例所示:

/**
* @constructor
*/
function A() {
/** @type Node */
this.x = document.createElement("p");
}

但是,IDE 无法识别 x 的类型。另一方面,像

这样的声明
/** @type Node */
var x;

确实有效,即在这种情况下,已知 x 具有 Node 的类型。

如果我添加

A.prototype.x = new Node();

对于第一个示例,x 将被称为Node 类型的变量。但是,此代码不会运行。

最佳答案

/** @type Node*/
A.prototype.x = undefined;

关于javascript - Eclipse/JSDT 中的类型声明/推断,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9411879/

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