Table of Contents
- Introduction
- Intellisense Support
- JavaScript Includes and Intellisense
- Intellisense Hints and Comments
- Conclusion
- Useful Links
- History
In today's AJAX (Asynchronous JavaScript And XML) world, one of the most obviously missing features of Visual Studio is the support for rich JavaScript Intellisense. Sure, a limited support for variable and function completion is available. It dates back as far as Microsoft Visual InterDev. However, it is minimalist at best. On more than one occasion, I had to venture outside of Visual Studio, my tool of choice for ASP.NET applications. To gain access to more advanced JavaScript features, such as the support for Intellisense with external includes, I had to use other IDEs, such as Eclipse and Aptana.
Finally, the latest version of Visual Studio (Visual Studio 2008) introduces the much-needed improvements in the JavaScript handling area. We will take a look at some of them.
To begin with, the Intellisense support for JavaScript is much improved. Since JavaScript is a weakly typed language, it is to be expected that some Intellisense limitations will stem from the language itself. In Visual Studio 2008, it appears that every effort is being made to compensate for these.
An inclusion of keywords in Intellisense, for example:
Since we are on the topic of efficiency, another neat feature introduced by Visual Studio 2008 is the transparency of the Intellisense window. Simply click the Control (Ctrl) key while the window is displayed, and you can see the code underneath it.
As mentioned above, while working on JavaScript intensive projects, one of the features I missed most often was the support for Intellisense from external library files. Visual Studio 2008 solves this problem by exposing all public
methods and properties to the page you are including it in. For example:
Include YAHOO animation library file in your page:
<script src="yui/build/animation/animation.js" type="text/javascript"></script>
And immediately you get the following in your Intellisense window:
Visual Studio 2008 takes this concept a step further by allowing you to reference one include from inside another. For example, let's assume, that your JavaScript code is in an include file, and within your include you're using a third party solution, like Mootools or Script.aculo.us. In order to get the list of members from another file within your include you need to place a reference comment at the top of it. For example:
/// <reference path="yui/build/yahoo-dom-event/yahoo-dom-event.js" />
/// <reference path="yui/build/animation/animation.js" />
The last new feature we'll look at is the Intellisense hints. You can add hints to your code in the following manner:
function SayHello(firstName, lastName)
{
return "Hello " + firstName + " " + lastName;
}
Notice, that the comments block is within the function block, not directly above it, as it would be in VB.NET or C#.
By using the above code, you get the following in your ASPX file:
And then the parameter details will also display your comments:
Notice, that, in the above example, type attributes are specified as string
. These are provided for informational purposes only, but you may find them useful when coding.
At the time of this writing, Intellisense hints and comments were only available from includes, not from the code block within your current page. That means, that the above example will display comments and hints only when you place it in an include file, and then reference it in your ASP.NET page. If, however, you place this code in the same ASP.NET page's script block, the comments and hints will not be shown. It will be interesting to see, where Microsoft takes this feature in the final release.
Visual Studio 2008 brings many new features that will make the coding experience more rewarding, and hopefully, more expedient. Throughout the previous Visual Studio releases, JavaScript IDE integration has been somewhat neglected, but, with the advent of AJAX and Web 2.0 applications, it is finally getting the attention it deserves.
- 4th November, 2007: Initial post