Domanda

/// <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.

È stato utile?

Soluzione

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.

Altri suggerimenti

This works for me in Visual Studio 2010 with the jQuery IntelliSense documentation included from the NuGet package (currently 1.6.1). There is one hack, but this is an example jQuery plugin with full IntelliSense of the jQuery instance.

/// <reference path="/Scripts/jquery-1.6.1.js" />
(function ($) {
    /// <param name="$" type="jQuery">
    ///     Pass me jQuery
    /// </param>

    // IntelliSense works here.
    $(".intellisense_work_here").add(".test", "<strong>it works<strong>");

    // Setting this locally enables IntelliSense  to work in the .each below.
    var $ = $;

    $.fn.makeThingsAwesomePlugin = function (options) {

        var defaults = {
            awesomeness: "really_awesome"
        };
        var options = $.extend(defaults, options);

        return this.each(function () {

            // intellisense work here    
            $(".someting_lame").addClass(options.awesomeness);
        });
    };
})(jQuery);
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top