Code <script language ="javascript" type ="text/javascript"> function add(x, y) { return x + y; } function substract(x, y) { return x - y; } function multiply(x, y) { return x * y; } function divide(x, y) { return x / y; }
function operate(opertor, operand1, operand2) { return opertor(operand1,operand2); } var i = operate(add, 2, 3); document.write(i);
var operators = { add: function(x, y) { return x + y; }, substract: function(x, y) { return x - y; }, multiply: function(x, y) { return x * y; }, divide: function(x, y) { return x / y; }, pow: Math.pow() };
function operator2(op_name, operand1, operand2) { if (typeof operators[op_name] =="function") return operators[op_name](operand1, operand2); elsethrow"This is a error!!"; }
var j = operator2("divide", 10, 2); document.write(j); </script>