Question

I'm using Visual Studio 2012 and building a JavaScript Windows Store App.

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. The same goes for "srcElement" in this line:

var nameInput = eventInfo.srcElement;

Is this to be expected or am I missing something?

Was it helpful?

Solution

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.

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?

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.

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?

OTHER TIPS

Norguard is right about the difficulties in providing suggestions for a dynamic language like JS. To help in situations like this, you can provide hints to the Visual Studio JavaScript editor using documentation comments. 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. Typing listView. will then show a completion list with suggestions for the ListView.

  • Jordan, Microsoft Visual Studio PM
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top