If you want to modify a value that is passed to a function, you need to pass a reference to it. Normally you would depend on a function returning a single value.
You can do this by creating an object, passing the object but mutating the values of the object's properties. This bridges the scope chain because the locally scoped copy refers to the outer scoped LValue.
This is demonstrated in the example.
<HTML> <HEAD> </HEAD> <BODY> <SCRIPT> myObject = new Object(); myObject.myVar = 22; callMe(myObject); document.write("<BR>"); document.write(myObject.myVar); function callMe(aValue) { document.write(aValue.myVar); document.write("<BR>"); aValue.myVar = 100; document.write(aValue.myVar); } </SCRIPT> </BODY> </HTML>
Prev | Home | Next |
Call a function | Up | Call 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. |