|
1 // Copyright 2009 the Sputnik authors. All rights reserved. |
|
2 // This code is governed by the BSD license found in the LICENSE file. |
|
3 |
|
4 /** |
|
5 * Reference to Self-Modifying Object remain the integrity |
|
6 * |
|
7 * @path ch08/8.7/S8.7_A2.js |
|
8 * @description Create a reference to the array, and change original array |
|
9 */ |
|
10 |
|
11 ////////////////////////////////////////////////////////////////////////////// |
|
12 //CHECK#1 |
|
13 // Create an array of items |
|
14 var items = new Array( "one", "two", "three" ); |
|
15 // Create a reference to the array of items |
|
16 var itemsRef = items; |
|
17 // Add an item to the original array |
|
18 items.push( "four" );var itemsRef = items; |
|
19 // The length of each array should be the same, |
|
20 // since they both point to the same array object |
|
21 if( itemsRef.length !== 4){ |
|
22 $ERROR('#1: var items = new Array( "one", "two", "three" ); var itemsRef = items; items.push( "four" );var itemsRef = items; itemsRef.length !== 4'); |
|
23 }; |
|
24 // |
|
25 ////////////////////////////////////////////////////////////////////////////// |
|
26 |
|
27 ////////////////////////////////////////////////////////////////////////////// |
|
28 //CHECK# |
|
29 // Create an array of items |
|
30 var items = new Array( "one", "two", "three" ); |
|
31 // Create a reference to the array of items |
|
32 var itemsRef = items; |
|
33 // Add an item to the original array |
|
34 items[1]="duo"; |
|
35 // The length of each array should be the same, |
|
36 // since they both point to the same array object |
|
37 if( itemsRef[1] !== "duo"){ |
|
38 $ERROR('#2: var items = new Array( "one", "two", "three" ); var itemsRef = items; items[1]="duo"; itemsRef[1] === "duo". Actual: ' + (itemsRef[1])); |
|
39 }; |
|
40 // |
|
41 ////////////////////////////////////////////////////////////////////////////// |
|
42 |