简体   繁体   English

为什么JavaScript Intellisense不能始终在Visual Studio 2012中运行?

[英]Why does JavaScript Intellisense not always work in Visual Studio 2012?

I'm using Visual Studio 2012 and building a JavaScript Windows Store App. 我正在使用Visual Studio 2012并构建一个JavaScript Windows Store应用程序。

For the most part, intellisense works, but for some things it does not. 在大多数情况下,智能感知是有效的,但在某些方面却没有。 I'm just wondering why. 我只是想知道为什么。 Here are a few examples: 这里有一些例子:

var ctl=document.getElementById("txtName").winControl;

Although other items show up, the "winControl" item does not appear in intellisense, yet it still works. 尽管显示了其他项目,但“ winControl”项目并未出现在智能感知中,但仍然有效。 The same goes for "srcElement" in this line: 这行中的“ srcElement”也是如此:

var nameInput = eventInfo.srcElement;

Is this to be expected or am I missing something? 这是意料之中的还是我缺少什么?

As you go deeper into JavaScript, unlike strongly-typed languages, it becomes more difficult to figure out what these values are going to be, unless the JavaScript code is written inside of an HTML page, which the editor can run through in real-time. 当您深入研究JavaScript时,与强类型语言不同,要弄清楚这些值将变得更加困难,除非将JavaScript代码编写在HTML页面内,编辑器可以实时运行该HTML代码。 。

var myFunc = function (evt) { console.log(evt); }

window.onclick = myFunc;

myFunc("Bob");

What is an IDE supposed to make of that, and what properties should evt have? 什么是IDE应该做的是,而且应该是什么性质evt有哪些?

If JavaScript were strongly-typed, and that function could only accept Event objects, or ClickEvent objects, then the IDE could know exactly what properties to expect. 如果JavaScript是强类型的,并且该函数只能接受Event对象或ClickEvent对象,则IDE可以确切知道期望的属性。

Just like .getElementById -- if one page has "myEl" as <a> and another page has the same ID as <canvas> then what should the properties be? 就像.getElementById一样-如果一个页面的<a>具有“ myEl”,而另一页面的<canvas>具有相同的ID,那么属性应该是什么?

Norguard is right about the difficulties in providing suggestions for a dynamic language like JS. 对于为诸如JS这样的动态语言提供建议方面的困难,Norguard的观点是正确的。 To help in situations like this, you can provide hints to the Visual Studio JavaScript editor using documentation comments. 为了在这种情况下提供帮助,您可以使用文档注释向Visual Studio JavaScript编辑器提供提示。 For example, I can use the following code: 例如,我可以使用以下代码:

/// <var type="WinJS.UI.ListView"/>
var listView = document.querySelector("#listView").winControl;

and the /// comment will associate the WinJS.UI.ListView type with my listView variable. // //注释会将WinJS.UI.ListView类型与我的listView变量关联。 Typing listView. 键入listView. will then show a completion list with suggestions for the ListView. 然后将显示一个完成列表,其中包含有关ListView的建议。

  • Jordan, Microsoft Visual Studio PM 乔丹,Microsoft Visual Studio PM

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

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