I see how the arguments of a function can be passed, displayed in and operated on in the following “findMax” function.
[code=php]
<!DOCTYPE html>
<html lang=”en”>
<head>
<meta charset=”UTF-8″ />
<title> HTML5 page </title>
</head>
<body>
<script type=”text/javascript”>
// Following from: http://www.w3schools.com/js/js_function_parameters.asp
function findMax() {
// alert(‘findMax: ‘+[].join.call(arguments, ‘ : ‘)); // this demo shows arguments as an array
var i, max = 0;
for (i = 0; i < arguments.length; i++) {
if (arguments[i] > max) { max = arguments[i]; } // shows arguments can be accessed
}
return max;
}
x = findMax(1, 123, 500, 115, 44, 88);
alert(‘maximum: ‘+x);
// Trying to go the other way: Array to arguments pseudo-array
tarr = [1,2,3,4,5,6,7,8,9];
function createArguments(tarr) {
// alert(‘create: ‘+[].join.call(arguments, ‘ : ‘)); // this demo shows arguments as an array
// for (var i=0; len=tarr.length, i<len; i++) { arguments.push(tarr[i]); } // cannot push an argument list
return tarr.toString(); // creates a string same as .join() which is NOT an arguments display
}
var args = createArguments(tarr);
alert(‘arguments: ‘+args);
alert(‘maximum (version 2): ‘+findMax(args)); // returns 0 because there are no args for findMax function
</script>
</body>
</html>
What I have NOT been able to accomplish, as tried above, is to go the other way:
Make an arguments (list, object, term?) from an array.
It this possible? Can an array be transferred into a arguments list and used in a different function?
?