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.

clok (1) [Avatar] Offline
#1
Hello,

This regards to the function net.CommandQueue.onload in Listing 6.1 on page 219.

I just noticed that the "this" keyword is misused in this function partially copied here:

net.CommandQueue.onload = function(loader) {
...
if (parseInt(lastUpdate) > this.lastUpdateTime) {
this.lastUpdateTime=lastUpdate;
}
....
this.onUpdate.call(this,elChild);
}

The "this" keyword does not point to the CommandQueue instance as suggested by the book, but rather to the instance of ContentLoader.

This is because of how net.CommandQueue.onload is called. Here is how:

1. First a new instance of ContentLoader is created. A reference to the function net.CommandQueue.onload is passed in as a parameter.

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

2. Then net.CommandQueue.onload is called within ContentLoader like this:

this.onload.call(this);

This is why the "this" keyword in net.CommandQueue.onload refers to the instance of ContentLoader.