Mimicking Casting with Visual Studio JavaScript IntelliSense

I am passing a jQuery object to a function from another file through an array like the following:

$(document).bind("loadStoreDisplayCallGoals", function(source, urlParams) { var selectedStoreDocument = urlParams["storeDocument"]; } 

selectedStoreDocument must be a jQuery object, however Visual Studio Intellisense will never recognize it as such. I tried to add the selectedStoreDocument extension using $.extend :

 // cast selectedStoreDocument to a jQuery type $.extend(selectedStoreDocument, $); 

However, the selectedStoreDocument extension destroyed all my jQuery methods ( .each , .find , etc.).

How can I get selectedStoreDocument to display as a jQuery object in IntelliSense? Please note that I am working in Visual Studio 2010.

+7
source share
3 answers

I created a separate file for the utility functions, and the second file for the utility functions + VSDoc.

utilities.js:

 function castToJQuery(item) { return item; } 

utility-vsdoc.js:

 function castToJQuery(item) { /// <summary> /// 1: $(item) - "Casts" the specified item to a jQuery object for the sake of Intellisense /// </summary> /// <returns type="jQuery" /> return $("dummy"); } 

Now I can call castToJQuery in any of my downstream files so that Visual Studio considers the dynamic property to be a jQuery object.

 var selectedStoreDocument = castToJQuery(urlParams["storeDocument"]); selectedStoreDocument.find("products"); 

Visual Studio now works with Intellisense for my dynamic urlParams ["storeDocument"].

+6
source

You cannot get intellisense for dynamically added properties. You need to define them statically (in the vsdoc or js file):

 $.selectedStoreDocument = function() { ///<summary>A Selected Store Document</summary> }; 
+2
source

You can specify documentation information for such a variable:

 $(document).bind("loadStoreDisplayCallGoals", function(source, urlParams) { /// <var type="jQuery"/> var selectedStoreDocument = urlParams["storeDocument"]; selectedStoreDocument._ } 

For more information see http://msdn.microsoft.com/EN-US/library/hh542722(VS.110).aspx

+1
source

All Articles