SharpGIS

#GIS from a .NET developer's perspective

Visual Studio 2008 JavaScript Intellisense - Take Two

...Not for namespaces either.

We all know that global variables in JavaScript API’s are bad (although they are usually OK in application-specific contexts). So therefore the solution is to create a namespace and put all your objects inside that. That way you only end up with one global, the name of the “root” namespace. You should choose a root name that probably isn’t used by anyone else, like your company name or similar.

With the Microsoft AJAX Clientside Library, Microsoft gave us registerNamespace for this thing, like for instance:

Type.registerNamespace('myCompany.Utility.Math');
myCompany.Utility.Math.Calculator = function() { }
myCompany.Utility.Math.Calculator.prototype = {
 add : function(a,b) { return a+b; }
}
myCompany.Utility.Math.Calculator.registerClass('myCompany.Utility.Math.Calculator');

Basically what Type.registerNamespace does is creating a set of objects:

myCompany = {};
myCompany.Utility = {};
myCompany.Utility.Math = {};

There's is just one problem to this. Visual Studio 2008’s intellisense is not evaluating the result of Type.registerNamespace, and thus, never realizes that those three objects exist. The result is that you don’t get any intellisense on your namespaced objects. Bummer! The workaround is either to create the namespaces yourself (like above) before calling Type.registerNamespace, or create aliases for the classes (which would re-introduce the globals we were trying to get rid of in the first place).

Of course I considered this to be a bug, and as I mentioned at the end of my previous post there was a problem with using namespaces and JavaScript Intellisense in Visual Studio 2008, that I had submitted a bug report for.

I was surprised how quickly they investigated and escalated the issue, but my biggest surprise was the result, which is pretty much this:

We are not going to support the pattern we told you to use until version 20xx.

OK, maybe a bit over-dramatized but still... It's funny because they are actually able to give me full intellisense for the namespaced objects in the MS AJAX Sys.* namespace (but they probably hardcoded that in there ;-)

With this and the fact that javascript files included by webcontrols are not intellisensed either, I’ve come to the conclusion that the hyped and long awaited JavaScript Intellisense in Orcas is pretty much useless. What do you think?

Comments are closed