Re: Custom JavaScript object wrapping SOAP calls

Martin Honnen <[email protected]>
Newsgroups gmane.comp.mozilla.devel.xml
Organization Liberty Development
Message-ID <[email protected]>

xxx wrote:


> I'd like to do something like this...
> 
> var mycall = new MyCallWrapper("RemoteMethodName", myparamarray);
> mycall.execute(mycallback);
> 
> ...and have mycallback be called on return of the remote method.  Here's the 
> idea of the MyCallWrapper class...
> 
> function MyCallWrapper(methodname, parameters) {
>     this.method = methodname;
>     this.params = parameters;
>     this.call = new SOAPCall();
>     // set info on the call object...
> }
> MyCallWrapper.prototype.execute = function (callback) {
>     this.callback = callback;
>     this.call.asyncInvoke(this.genericCallback);

Here you are simply passing in a function object (this.genericCallback) 
to the asyncInvoke method, a function object in JavaScript is not bound 
to an object so when asyncInvoke (later) calls that function object it 
indeed has no knowledge about MyCallWrapper or its "instances".
Sometimes closures help to solve that so you could do (untested!, simply 
following the scheme your example gives, without looking further into 
what SOAPCall, asyncInvoke etc need)

function bindCallback (callWrapper) {
   return function (response, call, error) {
     // not sure what genericresponse is or where that would come from
     callWrapper.callback(genericresponse, genericerror);
   }
}

and then above instead of
   this.call.asyncInvoke(this.genericCallback);
you could call
   this.call.asyncInvoke(bindCallback(this));




-- 

	Martin Honnen
	http://JavaScript.FAQTs.com/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.