Quick Tip: Autocomplete for Javascript in Visual Studio

The Web

Recently I have been doing a lot more web programming with the company I work for and I have really been enjoying it.  I’m stretching myself again learning new things about html, css, and javascript and how to do them all better.  I have learned things like self executing functions,  more about scope and how awesome that can be, and how to get your tools ( in this case Visual Studio 2012 ) to help you out.

The Tools

Autocomplete comes in handy because we just can’t remember it all and that’s ok.   Javascript is a loosely typed language and doesn’t lend itself to autocomplete very well.  Visual Studio can autocomplete some things that are defined in the file you are currently working by default, but what if you need more information and what if you need that information in another file?  Well there is a solution.

Enough Already This Is Suppose To Be A Quick Tip

Well ok then.

 

Reference Directives

To get Visual Studio to tell you about javascript objects in other files in the current file do this:

/// <reference path="path/to/myfile.js" />

 

More Information About A function And Within A Function

Because javascript is loosely typed when we write



function myfunc(a) {

//work with a here

}

we may not know what “a” is suppose to be or how to use it.  Even if we do, we would still like autocomplete to function; Visual Studio has an answer for this as well.



function myfunc(a) {

///<summary>summary about the function</summary>
 ///<param name="a" type="String">what a is; this will give you auto complete</param>
 ///<returns type="String">what I'm returning; this will give the calling function autocomplete!!! Double Bonus!!</returns>

//do stuff with a with auto complete; yay!!!

}

Further Reading

Javascript Intellisense In Visual Studio

The <param>

For fun and learning

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s