Recipe: How to make use of intellisense feature when coding JavaScript in Visual Studio 2010

Motivation

You have included a JavaScript library and you want to make use of intellisense while coding JavaScript in Visual Studio but you couldn’t find the correct way for it.

Recipe

Ingredients

  • 1 JavaScript library to include (i.e. jslinq.js)
  • 1 -vsdoc.js file of library you want to include (i.e. jslinq-vsdoc.js)

Directions

  • Include the -vsdoc.js file. You don’t need to include it in the same folder where your actual .js file is located.  However, it is more practical to keep them as close as possible for the ease of maintenance, code navigation and delightful presentation 🙂

image

  • Put the following code at the top of the JavaScript file (i.e. map.js) where you call functions of the included library (i.e. JSLINQ.js).
/// <reference path="~/Scripts/jslinq/JSLINQ-vsdoc.js" />

Tip of the recipe

    • This “<reference … /> codes” must be the first code in you calling JavaScript file (i.e. map.js)
    • The referenced path must be the path of –vsdoc.js file. Not the path of the actual js file !

 

  • Create an object of the library.

image

Tip of the recipe

  • If you create in the wrong way, although you can still use the object as expected, the intellisense won’t work.
  • Now you can make use of intellisense while you code JavaScript.

image

  • That’s it enjoy your code 🙂
Advertisements