Visual Studio 2010 Javascript Intellisense 无法正常工作
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
无论如何,“成功”回调内部的
返回
都不会起作用。它将从 that 函数返回,但不会关注返回值,特别是“success”函数的返回值将不会从“MyFunction”返回值。如果您想要“MyFunction”获取一个值并允许某些代码对其进行处理,则必须将该代码传递给“MyFunction”并在“success”函数中调用。因此,
您可以更改“MyFunction”,这样您就可以执行以下操作:
该函数看起来像这样:
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:
you'd change "MyFunction" around so that you could do this:
The function would look something like this: