如何在 Visual Studio .NET 2008 中保留 JavaScript 全局变量的智能感知

发布于 2024-10-27 13:21:51 字数 589 浏览 3 评论 0原文

我有一个 JavaScript 包装器,在主体加载时初始化它并设置为全局变量。创建对象后,我就有了完整的智能感知,但是当稍后从另一个函数引用它时,智能感知丢失了。我认为这是因为动态类型:

var myWrapper;

function onload() {
    myWrapper = new Wrapper(args);
    myWrapper. //Intellisense here.
}

function whatever() {
    myWrapper. //Intellisense lost.
}

我通过假装在代码之前再次创建对象,然后删除该行来解决此问题:

function whatever() {
    myWrapper = new Wrapper(); //Pretend to create object again.
    myWrapper. //Intellisense returns!
}

Has the inference was returned in Visual Studio 2010,或者有什么方法可以告诉 JavaScript关于我目前正在处理的对象类型?

I have a JavaScript wrapper that I initialize on body load and set to a global variable. Just after creating the object, I have full intellisense, but when referring to it later, from another function, the intellisense is lost. I presume this is because of dynamic typing:

var myWrapper;

function onload() {
    myWrapper = new Wrapper(args);
    myWrapper. //Intellisense here.
}

function whatever() {
    myWrapper. //Intellisense lost.
}

I get round this by pretending to create the object again before my code, and then deleting the line:

function whatever() {
    myWrapper = new Wrapper(); //Pretend to create object again.
    myWrapper. //Intellisense returns!
}

Has the inference been improved in Visual Studio 2010, or is there any way to tell JavaScript about the type of object I'm currently working on?

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

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

发布评论

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

评论(1

优雅的叶子 2024-11-03 13:21:51

除非你告诉它是什么类型(通过使用 new 关键字,否则将很难猜测它是什么......

例如,考虑以下内容

var myArray;
myArray. //intellisense has no idea this is meant to be an array

var myArray = new Array();
myArray. //intellisense knows it is a array (.pop, .push, .join etc)

,所以是的,也许允许你的对象被设置(没有像你一样的参数)并将其放在顶部......

var myWrapper = new Wrapper();

// now whenever myWrapper is used, intellisense
// should appear (provided it knows what Wrapper is

Unless you tell is what type it is (by using the new keyword, it's going to have a hard time guessing what it is...

For example, consider the following

var myArray;
myArray. //intellisense has no idea this is meant to be an array

var myArray = new Array();
myArray. //intellisense knows it is a array (.pop, .push, .join etc)

so yeah, perhaps allow your object to be set (Without args as you have) and put it at the top...

var myWrapper = new Wrapper();

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