7

I am passing in a jQuery object into a function from another file via an array like the following:

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

selectedStoreDocument should be a jQuery object, however Visual Studio Intellisense will never recognize it as such. I tried adding extending selectedStoreDocument with $.extend:

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

However, extending selectedStoreDocument wiped out all of my jQuery methods (.each, .find, etc.).

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

3 Answers 3

6

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

utilities.js:

function castToJQuery(item)
{
    return item;
}

utilities-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 to make Visual Studio think a dynamic property is a jQuery object.

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

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

2
  • Interesting approach. Can you post a screenshot of how it looks?
    – Mrchief
    Commented Jul 26, 2011 at 15:18
  • I'll try to add some screenshots later today
    – Peder Rice
    Commented Jul 26, 2011 at 15:33
2

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

$.selectedStoreDocument = function() {
     ///<summary>A Selected Store Document</summary>
};
5
  • 1
    So there's no way to "cast" something for intellisense?
    – Peder Rice
    Commented Jul 26, 2011 at 15:00
  • Javascript is not compiled language, nor does VS has a language srvice provider that can evaluate the language and provide c# like intellisense for you.
    – Mrchief
    Commented Jul 26, 2011 at 15:04
  • @Pedar, you should try ReSharper 6, its javascript engine is considerably more robust than the stock VS facilities for purposes of intellisense (and refactoring, etc.)
    – Kirk Woll
    Commented Jul 26, 2011 at 15:05
  • No, I understand that. I just wasn't sure if there was a comment tag available for variables akin to ///<summary>A Selected Store Document</summary> that I could use to "cast" my variable.
    – Peder Rice
    Commented Jul 26, 2011 at 15:07
  • Not sure what you mean by cast. Here's a reference to available tags: msdn.microsoft.com/en-us/library/bb385682.aspx. Are you looking for param type?
    – Mrchief
    Commented Jul 26, 2011 at 15:11
1

You can specify documentation information for a variable like this:

$(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

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.