Friday, September 3, 2010

Adding jQuery intellisence in your javascript in VS2008

I've been developing Websites in Visual Studio and I am very fond of its intellisence.  Intellisence helps a lot in your skills and most of the time, makes you more productive.  One of the great thing also in VS intellesence is you can create a summary of the public or private method/class you made, where not just by showing it to you the methods/class but also providing you a brief summary of how the method/class works or what is the purpose of the method/class depending on how you or a built-in method is described in your summary.

But when I started to add some javascript codes to my project sometimes I forgot some functions or properties of javascript, specially those in jQuery and the once that I have created so I keep on changing page just to see what are those functions and/or properties.  So I search the web and found out this very helpfull blog of ScuttGu's on jQuery Intellisen in VS 2008

After I have completed the steps on how to Enable jQuery Intellisense in VS 2008.  It works terrific! But only in the same page as where I put my <script> block that calls out the jQuery js file.  Because whe I start coding a separate .js file, the jQuery intellisence is gone so I wonder why the jQuery intellisense will not show in the separate .js file.  And I found out a post of Reference JS file in Other JS File and Intellisence.  It works like a charm. 

So when I want to access an intellisense of jQuery in my Person.js file, I'll just add

/// <reference path="path-to-my-jquery.js" />

at the first line of my Person.js file.  If you want to add more intellisense in your .js file just add the reference path to your other .js file.

And in addition to that.  I've tried to add some summary to my functions and properties that I've created so I can review them without going back to the .js file where I wrote the functions.

Person.ComputeAge = function(yearToday, birthYear) {
    /// <summary>
    ///    Compute the age of the person
    /// </summary>
    /// <param type="Int">Current Year</param>
    /// <param type="Int">Birth Year</param>
   
    ...
    // my code goes here
    ...

}

so when I tried to access Person.ComputeAge() it will display a summary of the function just like the intellisense of Visual Studio.

No comments:

Post a Comment