为什么 VSDoc IntelliSense 不能在 jQuery 无冲突包装器内工作?

发布于 2024-10-27 16:11:38 字数 406 浏览 8 评论 0原文

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

Visual Studio 2008 有解决方法吗? SP1 修补程序已应用,这就是 IntelliSense 在无冲突包装器外部工作但在内部没有 bueno 的原因。有些人说添加 param 注释,但是,唉,这对我来说也不起作用。

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

仅此而已 2024-11-03 16:11:39

这是因为该函数的定义不知道 jQuery 在其内部表示美元。以此为例:

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

您的函数无法知道您传入的内容的定义。由您的函数来弄清楚并确保您的参数有效。

函数的定义和函数的执行是两个独立的事情。您不会获得函数定义内的函数参数的智能感知。

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.

二货你真萌 2024-11-03 16:11:39

这在 Visual Studio 2010 中适用于我,其中包含 NuGet 包(当前为 1.6.1)中的 jQuery IntelliSense 文档。有一个 hack,但这是一个示例 jQuery 插件,具有 jQuery 实例的完整 IntelliSense。

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

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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文