开发者

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

开发者 https://www.devze.com 2023-02-21 02:34 出处:网络
/// <reference path=\"jquery-1.5.vsdoc.js\" /> // IntelliSense works here. function ($, window, document, undefined) { /// <param name=\"$\" type=\"jQuery\" />
/// <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, documen开发者_C百科t);

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.


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.


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);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号