I highlighted the lines of codes that I dont understand above.I dont understand the code var command = net.CommandQueue.sent[id];. How come this code need to be coded like that? Is it possible to change it like this: var command = this.sent[id];. Since this refers to net.CommandQueue then the code should work right?

Because the variable "other" inside the function refers to the variable "elodie" outside the function, since the the "elodie" object is passed to the function as a parameter.

alcatraz678 said:

Should it be just other?

No

alcatraz678 said:

Because other does not have a first property right?

Yes it does. As I said, "other" refers to "elodie", and "elodie" is an instance of the Person class, and the Person class has a "first" property, therefore the "elodie" Object also has the "first" property, and seeing as "other" refers to "elodie" that also has the "first" property.

Why does the this.owner.id needs to have this in the code? Couldn't it be just owner.id? Would it work the same or will it have different behaviour?

I'm not sure, there is not enough code to go by to answer this question. You could test it of course, see if it works

alcatraz678 said:

this.field = field;this.value = value;

These two lines of codes doesn't use this at all.Why? Would it be different if I use this.field = this.field?

Yes that would be differentthis.field = field => Set the property "field" in the object to the value of the parameter "field" given to the functionthis.field = this.field => Set the property "field" in the object to the value of the property "field" in the object. So in end-effect this does nothing.

Why does the this.owner.id needs to have this in the code? Couldn't it be just owner.id? Would it work the same or will it have different behaviour?

Both this.owner.id and the owner that's passed in to the function refer to elements on the page. They both can refer to different ones though.

The one that goes this.owner.id is the existing one that is already assigned to the UpdatePropertyCommand object.

The one passed to the function as owner is a reference to a different page element.

Both this.owner and owner refer to very different things, that may or just as easily may not refer to the same element. this.owner is the pre-existing one, and the owner that's passed to the function is a different one.

This line is adding a function to planets.commandsThe function that is added is called UpdatePropertyCommand, and is called with three arguments. owner, field and value.

this.id = this.owner.id+"_"+field;

The this keyword here refers to the current object, which in this case could quite easily be planets.commandsWherever you see the this keyword, you can mentally replace that with planets.command, or some other object that is specified to be the current object.

There are two separate things here that are being referred to as owner. One of these things is a property on the current object that is called owner. The other of these things is the variable called owner that was passed to the function.All references to the variable called owner that is passed to the function, could easily be renamed to something else, such as newOwner, without affecting in any way the completely separate property called owner that is on the current object.So, the above line takes owner element from the current object, which is very different from the owner that is passed to the function. The line takes the element's property called id, adds a string to it, and assigns that combination to a property of the current object called id

this.obj = owner;

This line uses the element that the UpdatePropertyCommand function was called with. The element in the owner variable is a very different one from that which the current object refers to.The above line tells a property called obj on the current object, to refer to the element that was passed to the function under the name of owner.

this.field = field;

This line sets a property called field on the current object, to be the same as the one that was passed to the function in the variable called field.

this.value = value;

This line sets a property called value on the current object, to be the same as the one that was passed to the function in the variable called value.

Because the variable "other" inside the function refers to the variable "elodie" outside the function, since the the "elodie" object is passed to the function as a parameter.

No

Yes it does. As I said, "other" refers to "elodie", and "elodie" is an instance of the Person class, and the Person class has a "first" property, therefore the "elodie" Object also has the "first" property, and seeing as "other" refers to "elodie" that also has the "first" property.