You are here: irt.org | About | Feedback | 4278 [ previous next ]
Feedback on:
irt.org FAQ Knowledge Base Q1590
Sent by
T.J. Crowder on November 16, 2002 at 06:54:12:
Worth:
Not worth reading
Length:
Just right
Technical:
Just right
Comments:
Hard to know what to put on the rating radio buttons in the feedback page. The problem is that the article is just plain wrong. In JavaScript, *all* method parameters are pass-by-value. What the author doesn't understand, or doesn't explain correctly, is what the "value" is when you pass an object reference. The value is the *reference* to the object; this is very, very different from passing a parameter by reference, even though the word "reference" is used in each case.
Here's how you can tell: If you assign a value to the variable that was passed in, does it change the value of *that variable* in the calling function? The example given does not, because it doesn't try to. This code:
function byReference(an_object) {
an_object.a_property *= an_object.a_property;
}
*Isn't* changing an_object, it's changing a_property, a very different thing. The proper test, just as with the a_variable test above it, would be:
function byReference(an_object) {
an_object = (some other object);
}
...which has no effect on the object reference in the calling code (it still refers to the same object, not the one assigned in byReference).
--
T.J. Crowder
tjirt@crowder.org
DO NOT ADD ME TO ANY MAILING LISTS AT ALL, NONE, NADA.
DO NOT SELL/GIVE/EXCHANGE MY EMAIL ADDRESS WITH ANYONE, AT ALL, FOR ANY REASON.