Passing a value by reference means that you pass a pointer to the data value. This means that when you copy the reference to another variable, you then have two variables pointing at the same data.
The data for both is identical. Modifying the data value pointed at by one, changes the value for the other variable also.
Non-primitive values (objects) are passed in this manner.
Note that although JavaScript has a good pass-by-reference technique built-in to the implementation, it does not support pointers as a specific data type as the C language does.
Passing a value by reference into a function allows the function to make changes that are visible outside the function.
In JavaScript, you cannot manipulate these parameter passing mechanisms. It will choose to pass by value or by reference according to the data type of the value being put into the argument. This is often the result of evaluating an expression. JavaScript takes care of all the type conversions for you.
Prev | Home | Next |
BUTTON.value | Up | By value |
JavaScript Programmer's Reference, Cliff Wootton Wrox Press (www.wrox.com) Join the Wrox JavaScript forum at p2p.wrox.com Please report problems to support@wrox.com © 2001 Wrox Press. All Rights Reserved. Terms and conditions. |