第一种 正常形式:
function add(a,b)
{
return a+b;
}
?
第二种 构造函数
注意F大写,参数与主体都用引号包起来
var add=new Function("a","b","return a+b");
?
第三种 直接变量赋值
函数可以当成变量来传递
var add = function (x, y) {
return x + y;
}
var subtract = function (x, y) {
return x - y;
}
var operate = function (operator, operand1, operand2) {
return operator(operand1, operand2);
}
alert(operate(subtract,10, 5));
?
