HTML and CSS Reference
In-Depth Information
Listing 5.9 Accessing properties with strings
function addToArray() {
var targetArr = arguments["0"];
var add =, 1);
return targetArr.concat(add);
Some browsers like Firefox optimize arrays, indeed treating numeric property
identifiers as numbers. Even so, the properties can always be accessed by string
5.2.2 Formal Parameters and arguments
The arguments object shares a dynamic relationship with formal parameters;
changing a property of the arguments object causes the corresponding formal
parameter to change and vice versa as Listing 5.10 shows.
Listing 5.10 Modifying arguments
TestCase("FormalParametersArgumentsTest", {
"test dynamic relationship": function () {
function modify(a, b) {
b = 42;
arguments[0] = arguments[1];
return a;
assertEquals(42, modify(1, 2));
Setting the formal parameter b to 42 causes arguments[1] to update ac-
cordingly. Setting arguments[0] to this value in turn causes a to update as well.
This relationship only exists for formal parameters that actually receive values.
Listing 5.11 shows the same example in which the second argument is left out when
calling the function.
Listing 5.11 No dynamic mapping for missing parameters
Search WWH ::

Custom Search