1

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?

1 Answer 1

2

You can put put it inside an anonymous function, for which you use the same function signature as the expected callback.

function Do(caller)
{
   MyService.GetClient(some_id, function(webServiceResult) {
       CallBackGetClient(webServiceResult, caller);
   });
}

Here you are passing an anonymous function to GetClient as 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 real CallBackGetClient, adding caller as a second argument. This works because caller gets "trapped" inside the scope of the anonymous function so it'a still usable.

And this right here is the best thing about Javascript.

Sign up to request clarification or add additional context in comments.

3 Comments

How then get both two in CallBackGetClient ?
CallBackGetClient will look like this: CallBackGetClient(WebServiceResult, caller) then?
I think I understand what you're after. I updated the answer. Hope that helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.