Search code examples
intellisensevisual-studio-2008-sp1jqueryvsdoc

Why doesn't VSDoc IntelliSense work inside of a jQuery no-conflict wrapper?


/// <reference path="jquery-1.5.vsdoc.js" />
// IntelliSense works here.

function ($, window, document, undefined) { /// <param name="$" type="jQuery" />
    // IntelliSense  does not work here.

}(jQuery, this, document);

Is there a workaround for Visual Studio 2008? The SP1 hotfix has been applied and is the reason the IntelliSense works outside of the no-conflict wrapper but, inside, no bueno. Some have said to add the param annotation but, alas, that doesn't work either for me.


Solution

  • It's because the definition of the function doesn't know that jQuery means dollar inside of it. Take this for example:

    var wrapper = function($, window, document, undefined) {
        // this function doesn't know what dollar is
    };
    
    // it could be called like this:
    wrapper(jQuery, window, document, undefined);
    
    // or like this:
    wrapper(1, 2, 3, 4);
    

    Your function cannot know the definition of what you are passing in. It is up to your function to figure that out and make sure your arguments are valid.

    The definition of the function and the execution of the function are two separate things. You will not get intellisense for function arguments inside of the function definition.