michael@0: // Copyright 2009 the Sputnik authors. All rights reserved. michael@0: // This code is governed by the BSD license found in the LICENSE file. michael@0: michael@0: /** michael@0: * Reference to Self-Modifying Object remain the integrity michael@0: * michael@0: * @path ch08/8.7/S8.7_A2.js michael@0: * @description Create a reference to the array, and change original array michael@0: */ michael@0: michael@0: ////////////////////////////////////////////////////////////////////////////// michael@0: //CHECK#1 michael@0: // Create an array of items michael@0: var items = new Array( "one", "two", "three" ); michael@0: // Create a reference to the array of items michael@0: var itemsRef = items; michael@0: // Add an item to the original array michael@0: items.push( "four" );var itemsRef = items; michael@0: // The length of each array should be the same, michael@0: // since they both point to the same array object michael@0: if( itemsRef.length !== 4){ michael@0: $ERROR('#1: var items = new Array( "one", "two", "three" ); var itemsRef = items; items.push( "four" );var itemsRef = items; itemsRef.length !== 4'); michael@0: }; michael@0: // michael@0: ////////////////////////////////////////////////////////////////////////////// michael@0: michael@0: ////////////////////////////////////////////////////////////////////////////// michael@0: //CHECK# michael@0: // Create an array of items michael@0: var items = new Array( "one", "two", "three" ); michael@0: // Create a reference to the array of items michael@0: var itemsRef = items; michael@0: // Add an item to the original array michael@0: items[1]="duo"; michael@0: // The length of each array should be the same, michael@0: // since they both point to the same array object michael@0: if( itemsRef[1] !== "duo"){ michael@0: $ERROR('#2: var items = new Array( "one", "two", "three" ); var itemsRef = items; items[1]="duo"; itemsRef[1] === "duo". Actual: ' + (itemsRef[1])); michael@0: }; michael@0: // michael@0: ////////////////////////////////////////////////////////////////////////////// michael@0: