Visual Studio 2010 Javascript Intellisense 无法正常工作

发布于 2024-10-08 21:52:36 字数 2060 浏览 4 评论 0原文

Visual Studio 2010 和 Javascript Intellisense 有一个小问题。

我已经实现了一个具有一些“属性”的类,并且想要实现一个“静态”函数,该函数在返回 Json 对象的 ajax 请求之后返回该类的新实例。

像这样:

/// <reference path="jQuery/jquery-1.4.1-vsdoc.js" />
MyClass = function (options) {
    /// <summary>MyClass Description</summary>
    /// <param name="options" type="Array">Foo1 (string), Foo2(string)</param>
    /// <field name="Foo1" type="String">Foo1 Description</field>
    /// <field name="Foo2" type="String">Foo2 Description</field>

    // [...] Some Code

    // Properties
    this.Foo1 = options.Foo1;
    this.Foo2 = options.Foo2;
}

函数:

智能感知不工作:

MyClass.MyFunction = function () { 
    /// <summary>MyFunction Description</summary>
    /// <returns type="MyClass">MyClass</returns>

    $.ajax({
        type: 'GET',
        url: '/Foo/Bar',
        dataType: 'json',
        success: function (result) {
            return new MyClass(result);
        }
    });
}

智能感知工作:

MyClass.MyFunction = function () { 
    /// <summary>MyFunction Description</summary>
    /// <returns type="MyClass">MyClass</returns>

    var foo = new MyClass({'foo1': 'a', 'foo2': 'b'});
    $.ajax({
        type: 'GET',
        url: '/Foo/Bar',
        dataType: 'json',
        success: function (result) {
            foo = new MyClass(result);
            return foo;
        }
    });

    return foo;
}

当我从另一个函数调用该函数时,例如:

$(document).ready(function() {
    var foobar = MyClass.MyFunction(); // returns Object of type "MyClass"
    alert(foobar.Foo1); // At this Point, the intellisense doesn't work correct
});

我的智能感知不再工作(或使用双返回),因为 MyFunction 的返回在ajax 请求。如果我将 return 放在函数末尾,则智能感知将再次工作。但在这种情况下我有两个回报。第一个来自函数,第二个来自 ajax-success。

似乎 仅当 return 位于函数末尾时才起作用。这很糟糕,因为我只需要在 ajax 请求完成时返回一次。

我不知道如何处理这个问题。希望你能帮我解决这个问题:)

There's a little problem with Visual Studio 2010 and Javascript Intellisense.

I've implemented a class with some "Properties" and want to implement a "static" function, which returns a new instance of the class after an ajax-request which returns a Json-Object.

Like so:

/// <reference path="jQuery/jquery-1.4.1-vsdoc.js" />
MyClass = function (options) {
    /// <summary>MyClass Description</summary>
    /// <param name="options" type="Array">Foo1 (string), Foo2(string)</param>
    /// <field name="Foo1" type="String">Foo1 Description</field>
    /// <field name="Foo2" type="String">Foo2 Description</field>

    // [...] Some Code

    // Properties
    this.Foo1 = options.Foo1;
    this.Foo2 = options.Foo2;
}

And the function:

intellisense not working:

MyClass.MyFunction = function () { 
    /// <summary>MyFunction Description</summary>
    /// <returns type="MyClass">MyClass</returns>

    $.ajax({
        type: 'GET',
        url: '/Foo/Bar',
        dataType: 'json',
        success: function (result) {
            return new MyClass(result);
        }
    });
}

intellisense working:

MyClass.MyFunction = function () { 
    /// <summary>MyFunction Description</summary>
    /// <returns type="MyClass">MyClass</returns>

    var foo = new MyClass({'foo1': 'a', 'foo2': 'b'});
    $.ajax({
        type: 'GET',
        url: '/Foo/Bar',
        dataType: 'json',
        success: function (result) {
            foo = new MyClass(result);
            return foo;
        }
    });

    return foo;
}

When I call the function from another function, like:

$(document).ready(function() {
    var foobar = MyClass.MyFunction(); // returns Object of type "MyClass"
    alert(foobar.Foo1); // At this Point, the intellisense doesn't work correct
});

my intellisense isn't working anymore (or works with the double-return), because the return of MyFunction is within the ajax-request. If I place the return at the end of the function, the intellisense is working again. But in this case I have two returns. The first from the function and the second from the ajax-success.

It seems that the <returns...></returns> only works when the return is at the end of the function. That's bad, because I just need one return when the ajax-request is completed.

I don't know how to deal with this problem. Hope you can help me to fix this :)

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

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

发布评论

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

评论(1

傲世九天 2024-10-15 21:52:36

无论如何,“成功”回调内部的返回都不会起作用。它将从 that 函数返回,但不会关注返回值,特别是“success”函数的返回值将不会从“MyFunction”返回值。

如果您想要“MyFunction”获取一个值并允许某些代码对其进行处理,则必须将该代码传递给“MyFunction”并在“success”函数中调用。因此,

var thing = MyClass.MyFunction();
/*
  do stuff with "thing"
*/

您可以更改“MyFunction”,这样您就可以执行以下操作:

MyClass.MyFunction(function(thing) {
  /*
    do stuff with "thing"
  */
});

该函数看起来像这样:

MyClass.MyFunction = function (doStuff) { 
  /// <summary>MyFunction Description</summary>

  $.ajax({
    type: 'GET',
    url: '/Foo/Bar',
    dataType: 'json',
    success: function (result) {
        doStuff(new MyClass(result));
    }
  });
}

The return from inside the "success" callback is not going to work anyway. It'll return from that function, but nothing is going to pay attention to the return value, and in particular the return value from the "success" function will not be the return value from "MyFunction".

If what you want is for "MyFunction" to fetch a value and allow some code to work on it, then that code will have to be passed in to "MyFunction" and called in the "success" function. Thus, instead of:

var thing = MyClass.MyFunction();
/*
  do stuff with "thing"
*/

you'd change "MyFunction" around so that you could do this:

MyClass.MyFunction(function(thing) {
  /*
    do stuff with "thing"
  */
});

The function would look something like this:

MyClass.MyFunction = function (doStuff) { 
  /// <summary>MyFunction Description</summary>

  $.ajax({
    type: 'GET',
    url: '/Foo/Bar',
    dataType: 'json',
    success: function (result) {
        doStuff(new MyClass(result));
    }
  });
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文