Visual Studio 2008: Making (Intelli)sense of JavaScript

Published Sunday, August 03, 2008 10:44 AM

 We are all masters of efficiency. We ditched snail mail in favor of email. We do not try to remember the links we favor, instead we digg, kick, twitter, bookmark; We do not type web addresses, we search, when we search, we rely on word suggestions, past searches ... How convenient.

ASP .net intellisense to ASP .net programming is Google Suggest to google search. In visual studio 2005 and its precessors, we have very nice intellisense support on the server side. Very smart too. 

However with Javascript, intellisense is barely there. This is painful, since the world has turned and now the web wants to be predominantly JavaScript driven and client centric with the server's role be limited to mainly data provider.  

The good news is that Visual Studio 2008 has started to provide enormous support of Intellisense for JavaScript; the bad news is, not enough. But better use it than lose it.

 Intellisense for Common JavaScript Keyword, Classes, Standard method

 For example, if you type document, you will have the immediate suspects at your fingertips. Nice.

However, since JavaScript is a non-typed script language, that means, there is no type declaration, string vs int, so there is no intellisense support for string functions or math functions. Sort of like you do not have not declare you are female, male, animal or human being, therefore there is no predication the kind of behavior.

Intellisense for ASP .NET AJAX JavaScript extensions

 

$ sign is probably the very magic symbol in ASP .NET AJAX. $get is shortcut for Document.get(""), $addHandler for Sys.UI.DomEvent.addHandler. So whenever you type a $, Intellisense will intantaneously fill in with all of the suspects. One catch is that you must first drag and drop a ScriptManager control to page so Intellisense will know the presense of ASP .NET AJAX

Intellisense for external JavaScript

If you drag and drop an external JavaScript to your page, Intellisense will make an informative guess and lend you with its intelligence.  

However, I also tested it with JQuery, somehow it does not work.

JavaScript Doc comments and Intellisense

In C# and VB .NET projects,  special formatted and tagged XML comments can be used to generate an external Documentation (XML Comments Let You Build Documentation Directly From Your Visual Studio .NET Source Files), or Compiled HTML Help file (CHM).

. Now, with ASP .NET, xml comments in JavaScript can be used for the same.

While in C# and vb .net, comments are placed outside of a class, constructor, interface, method, as such:

/// <summary>
///
/// </summary>
/// <param name="strFilePath"></param>
public void LoadXMLFromFile(string strFilePath)

 In JavaScript, the right place for xml comments is inside the scoop:

/// <summary>
///
/// </summary>
/// <param name="strFilePath"></param>
function LoadXMLFromFile(string strFilePath)
{/// <summary>
///
/// </summary>
/// <param name="strFilePath"></param>
}

 

Standard xml comments tags are

summary: description of a class, constructor, method ...

param: parameters for a method

returns: return type of a method, if the method is to return anything

value: description for a property

field: "The field tag (which doesn't exist in C# and VB.NET because in those languages the summary tag can be used) is used inside of a class, interface or enumeration constructor to describe a field." (Betrand Le Roy)

Betrand Le Roy has a comphresensive post regarding The format for JavaScript doc comments.

XML comments can also aid Intellisense to aid us write code and provide meaningful suggestions.

For example, for a JavaScript function getQuote with xml comments

function getQuote(symbol) { /// <summary>get stock quote for a given symbol</summary> /// <param symbol="symbol">stock symbol</summary> /// <returns>string</returns> }

when i tried to invoke the function, intellisense helped me with this:

 ===

So that is the one greatest thing about vs 2008: Intellisense for JavaScript.  Scott Gu has an very authoritive post about this:

VS 2008 JavaScript Intellisense

Update:

I soon found a post about how to work around the Intellisense problem for JQuery:

jQuery Intellisense in Visual Studio

 kick it on DotNetKicks.com

by xxXd
Filed under:

Comments

# DotNetKicks.com said on Sunday, August 03, 2008 9:32 AM

You've been kicked (a good thing) - Trackback from DotNetKicks.com

This site

This Blog

Syndication

Sponsors

  • MaximumASP