I find the seperation of code between when using callbacks makes my code harder to understand and maintain.
How do you handle the problem?
Here are a couple of solutions I have come up with, using, as an exaple, asynch web service calls. Please let me know what you think, and and pros or cons that occur to you.
via closures:
sayHelloWithClosures: function ()
{
//Do something first
// The following call's signature is: ServiceName(SuccessCallback, FailureCallback);
TestBasicWebServices.SL.WebService1.HelloWorld(
function (result)
{
//Do something next
alert(result);
},
function (error)
{
//Do Exception
alert(error._message);
});
}
via recursion:
sayHello: function (result)
{
if (result == undefined)
{
//Do something first
// The following call's signature is: ServiceName(SuccessCallback, FailureCallback);
TestBasicWebServices.SL.WebService1.HelloWorld(this.sayHello, this.sayHello);
}
else if (typeof (result) == "string")
{
//Do something next
alert(result);
}
else
{
//Do Exception
alert(result._message);
}
}
No comments:
Post a Comment