Call by reference (Definition)

Calling functions and passing references to receiving LValues in the arguments.

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.

Example code:

   <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>