drfrench (1) [Avatar] Offline
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(

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
Re: Question about Listing 5.13

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.