Featured post
Visual Studio 2010 Javascript Intellisense not working properly -
there's little problem visual studio 2010 , javascript intellisense.
i've implemented class "properties" , want implement "static" function, returns new instance of class after ajax-request returns 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> // [...] code // properties this.foo1 = options.foo1; this.foo2 = options.foo2; }
and 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 call function function, like:
$(document).ready(function() { var foobar = myclass.myfunction(); // returns object of type "myclass" alert(foobar.foo1); // @ point, intellisense doesn't work correct });
my intellisense isn't working anymore (or works double-return), because return of myfunction within ajax-request. if place return @ end of function, intellisense working again. in case have 2 returns. first function , second ajax-success.
it seems <returns...></returns>
works when return @ end of function. that's bad, because need 1 return when ajax-request completed.
i don't know how deal problem. hope can me fix :)
the return
inside "success" callback not going work anyway. it'll return that function, nothing going pay attention return value, , in particular return value "success" function not return value "myfunction".
if want "myfunction" fetch value , allow code work on it, code have passed in "myfunction" , called in "success" function. thus, instead of:
var thing = myclass.myfunction(); /* stuff "thing" */
you'd change "myfunction" around this:
myclass.myfunction(function(thing) { /* stuff "thing" */ });
the function this:
myclass.myfunction = function (dostuff) { /// <summary>myfunction description</summary> $.ajax({ type: 'get', url: '/foo/bar', datatype: 'json', success: function (result) { dostuff(new myclass(result)); } }); }
- Get link
- X
- Other Apps
Comments
Post a Comment