Visual Studio 2010 Javascript Intellisense is not working properly

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:

/// <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 function:

intellisense does not work:

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:

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 a function from another function, for example:

$(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 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 .

, . , :)

+3
1

return "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));
    }
  });
}
+2

Source: https://habr.com/ru/post/1781264/


All Articles