1: function doSomething (operand,value){ 2: var expressionToEvaluate = value ;
3: for (i=2;i<arguments.length; i++){ 4: // note that the first parameter "operand"
5: // is accessed with its name and the rest are
6: // being accessed through the arguments Array
7: expressionToEvaluate+= operand + arguments [ i ];
8: }
9: return eval (expressionToEvaluate);
10: }
11:
12:
13: this can do another type of polymorphism :)
14: alert (doSomething('*',2,3,4,5)); 15: alert (doSomething('+',2,3,4,5));