The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

drfrench (1) [Avatar] Offline
#1
I have a couple questions about the CommandQueue listing (5.13) on page 199.

1. You call the ContentLoader with:

this.loader=new net.ContentLoader(
this.url,
net.CommandQueue.onload,net.CommandQueue.onerror,
"POST",data
);

Why didn't you choose to reference the onload and onerror methods as "this.onload" and "this.onerror?"




2. Looking at the net.CommandQueue.onload() function you have it defined as:

net.CommandQueue.onload=function(loader) {
...
}

Won't loader variable always be empty since it is a callback being invoked in the XMLHTTPRequest context? It isn't used anywhere in the body of the function.



3. Later on in the function mentioned in question 2 you say:

var command=net.commandQueue.sent[id];

Is this to imply that there is a global 'net.commandQueue' variable that has been instantiated before the callback has been invoked?

Thanks for the help!
davecrane (149) [Avatar] Offline
#2
Re: Question about Listing 5.13
Hi,

When I referenced things as net.CommandQueue.xyz rather than this.xyz, I was thinking of static methods as opposed to instance methods. The callback functions are stateless, so it was more efficient to have two functions sitting aroud on the heap, rather than two for every instance.

Dave