I use this function in javascript to call web service (WCF):
function Do(caller)
{
MyService.GetClient(some_id, CallBackGetClient);
}
function CallBackGetClient(WebServiceResult)
{
var result = WebServiceResult;
etc.
}
Now I want to pass parameter (caller) to CallBackGetClient function so I can make dictinction who called Do() function. How to pass a parameter?
You can put put it inside an anonymous function, for which you use the same function signature as the expected callback.
Here you are passing an anonymous function to
GetClientas the callback. That function will take the expected web service result as its argument, but inside that function, you’re turning around and invoking the realCallBackGetClient, addingcalleras a second argument. This works becausecallergets “trapped” inside the scope of the anonymous function so it’a still usable.And this right here is the best thing about Javascript.