One of the more interesting aspects about JavaScript is the idea that functions are objects and can be passed around like an input box, image or anything else you may have. Take a look at this code, for example:
<script type="text/javascript">
function multiply(){
var out=1;
for(var i=0; i<arguments.length; i++){
out *= arguments[i];
}return out;
}function add(){
var out=0;
for(var i=0; i<arguments.length; i++){
out += arguments[i];
}return out;
}function doAction(action){
alert(action(1, 2, 3, 4, 5));
}
</script><button onclick="doAction(multiply)">Test Multiply</button>
<button onclick="doAction(add)" >Test Add</button>

浙公网安备 33010602011771号