I have the following code from a javascript book and the callback seems to be passed an expression as an argument. Is that the case or am I seeing this wrong? I didnt know, even though it works, that that was possible.
function multiplybytwo(a,b,c,callback) {
var i, ar =[];
for(i=0;i<3;i++)
{
ar[i] = callback(arguments[i]*2);
}
return ar;
}
function addone(a) {
return a+1;
}
myarr =multiplybytwo(1,2,3,addone);
someFunc(1)is passing an expression to a function, it's just that the expression is a simple number,1- but you can put pretty much any expression, including things that call other functions, e.g.,someFunc(someOtherFunc(x*2) / 7 + (aThirdFunc() ? 1 : -1))