function fname(value1,value2, ...)
<TITLE>A function definition</TITLE>
for (i = 0;i < itemList.length;i++)
document.write("<LI>" + itemList[i] + "\n")
days = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
If evaluate() is a defined function, the following line will call the function:
i3 = evaluate (Tree)
This function may evaluate the members of the array tree to see how many match a certain criteria.
Another way to call a function is to tie it to an anchor:
Another way is to tie it to an event:
<A NAME="javatest" onClick="redirectLink()">redirecting</A>
This will cause the redirectLink() function to run when the text "redirecting" is clicked on. The text inside the anchor reference is not marked as a link, nor does the mouse change when placed over the text. This is one way to make truly invisible links, that no one would know had any function until they click on it.
- arguments - An array of arguments passed to the function. This is an array object which has a property of length which enables the programmer to tell how many arguments (or variables)are passed to the function.
- caller - The name of the function that called the function.
- prototype - Used to make more properties.
Using the Arguments Array
The arguments array is a member of every function. It can be used to determine how many variables are being passed to the function, and what they are, without each argument being explicitly declared in the function. The following example performs the same task as the above example:
var items = listItems.arguments.length
for (i = 0;i < items;i++)
document.write("<LI>" + listItems.arguments[i] + "\n")
The function may be called as follows:
Local variables may be defined inside functions. The following example uses the variables, sum and items as local variables.
var items = average.arguments.length
var sum = 0
for (i = 0; i < items;i++)
sum += average.arguments[i]
As in the example above, the return statement will return a value to the statement that invoked the function. In the above example, the average value is written to the document. The return statement will return the value as float, string, integer or whatever is appropriate for use.