IntelliSense VS08 within private closure

by jerone 17. July 2009 23:19

I love the VS08 Javascript IntelliSense; it's fast, useful and informative in combination with VSDoc.
The only bug I stumble up every time I code, is the IntelliSense within a private closure. I'll give an example of what I mean:

(function($) {  // private closure;
$(function() {
// do stuff;
});
})(jQuery);

The problem with above code is that the argument $ in the function isn't given the data from the variable jQuery. So the advantage of IntelliSense within the closure is totally lost.

But yesterday I come up with a solution for all server-side scriptwriters (in this case ASP.net) that works in 2 ways; usefulness and source.
The solution is useful in the way that it should add IntelliSense for the arguments with the least amount of code.
The other way is that it I don't want the solution to be seen in the page source. I like my source clean and informative.

So here's the solution:

(function($) {  // private closure;  <% /*debug*/ if (false) { %> 
$ = jQuery;
// <% } /*end debug*/ %>
$(function() {
// do stuff
});
})(jQuery);

The part that adds the IntelliSense is the $ = jQuery;. But the important part is the if (false) {. This causes the code to work while developing, but not to print it on the source.

After fixing these problems another problem raises. You can't add server-side inside Javascript, causes an error, which then stops the IntelliSense again. The solution for this problem was to put the server-side code in a Javascript comment. That easy and the server-side code still executes.

I hope other find this useful too, gr J

Tags: , , ,

C# | ASP.net | JavaScript | jQuery

Add comment




  Country flag

biuquotelink
  • Comment
  • Preview
Loading



Tag cloud

This will be shown to users with no Flash or Javascript.

Calendar

<<  July 2010  >>
MoTuWeThFrSaSu
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678

View posts in large calendar