So I'm trying to understand what actually works and what doesn't with Orcas JavaScript Intellisense. I've used Orcas for a bit now and unfortunately I've had little luck on getting Intellisense support with my non-MS AJAX libraries. My own libraries don't work and neither does anything in Prototype, Scriptalicious or jQuery.
It appears that Orcas does fine with any straight function and variable definitions. If I have an ASPX page or a backing .js file and all I have in there is plain functions as is often the case with front end UI code I get Intellisense on this functionality.
The real issue has to do with class/object recognition. The problem there of course is that there are many, many different ways in JavaScript to define a 'class' (there really are no classes only closures that act like them <s>) and Orcas Intellisense only supports some of these formats.
So I set up a a sample JS file that checks for different class formats and how the Intellisense works for them. I created a simple ASPX page and added a reference to a script file. The comments indicate whether the structure is visible to Intellisense.
<script src="test.js" type="text/javascript"></script>
And then created the JS file with the following:
// this works fine
function HelloWorld(name)
{
alert("Hello " + name);
return false;
}
// Class as closure - doesn't work
function MyClass1()
{
this.myProperty = "Test";
this.myProperty2 = 0;
this.myMethod = function(input)
{
return 0;
}
}
// JSON static Class syntax - works
var MyStaticClass2 =
{
myProperty: "Test",
myProperty2: 0,
myMethod: function()
{
return 0;
}
}
// Prototype syntax - works
function MyClass3()
{
}
MyClass3.prototype =
{
myProperty: "Test",
myProperty2: 2,
myMethod: function(num)
{
// <value type="number" ></value>
return 0;
}
}
// *** Additional Prototype assignments - works
MyClass3.prototype.myProperty3 = 3;
// *** Direct property assignment - doesn't work
MyClass3.myProperty4 = 4;
I might be missing other ways here - if you see one of those leave a comment and I'll add it here. It seems it would be good to know what does and doesn't work.
So it looks like Orcas supports only prototype assignment syntax to figure out what 'members' are available on a class. It doesn't try to deal with direct class instances - maybe understandably so because it gets pretty difficult to determine when a property is assigned otherwise.
Further, if I'm inside the actual test.js file and in a method of a class (even one that is externally visible to Intellisense) I still don't get Intellisense on the this. pointer.
Syntax Parsing Errors make Intellisense fail entirely
It seems if there is any sort of syntax error or something that the Orcas Intellisense parser doesn't understand the entire Intellisense for the page comes to a stop. For example, if I add Prototype.js to the same page that loads the Test.js file, the Intellisense for Test.js and even functions in the local page file stops working. Not sure if that's intended behavior or a bug at the moment.
I suppose it's disappointing especially since I've been using Aptana, which does all of this fine, but of course it lacks the Visual Studio integration. For reference, here's a screen shot of typing this. inside of the test.js class in the Aptana editor:
Notice that in Aptana all three of the classes are visible and Intellisense picks up internal members within classes. It also recognizes closure based classes (although for some odd reason the plain HelloWorld function is missing) and figures out assignments in code in most cases.
Another extremely helpful feature that I wish was available in Visual Studio is the Function/Class list. The Outline window in Aptana is probably the main reason I use it - it let's me navigate large JS documents and classes. There's nothing like this in Visual Studio 2008 yet I think this is a crucial feature.
Although I like Aptana and I use it when doing heavy JavaScript editing, the actual editing experience in that environment is not nearly as smooth as in Visual Studio. It's also suboptimal for editing JS code inside of ASPX pages. That's why I was so hopeful that we'd get support along these lines in Visual Studio.
Hopefully there's more to come in coming betas.