There's a small issue with Visual Studio 2010 and Javascript Intellisense.
I have implemented a class with some “properties” and want to implement a “static” function that returns a new instance of the class after an ajax request that returns a Json-Object.
Same:
MyClass = function (options) {
this.Foo1 = options.Foo1;
this.Foo2 = options.Foo2;
}
And function:
intellisense does not work:
MyClass.MyFunction = function () {
$.ajax({
type: 'GET',
url: '/Foo/Bar',
dataType: 'json',
success: function (result) {
return new MyClass(result);
}
});
}
intellisense:
MyClass.MyFunction = function () {
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 a function from another function, for example:
$(document).ready(function() {
var foobar = MyClass.MyFunction();
alert(foobar.Foo1);
});
my intellisense no longer works (or works with double return), because the return of MyFunction is within the ajax request. If I return at the end of the function, intellisense works again. But in this case, I have two returns. The first of function and the second of ajax success.
, <returns...></returns> , . , , ajax .
, . , :)