oggiemc
asked on
Function passed to function
Hi All,
Can someone explain to me how the attached code works?
I understand the 3 and 4 are passed as the x and y parameters and the function is passed as the z parameter.. But i don understand what parameters are being passed to: function(x,y) { return x * y}??
Also, what is happening in the following line:
alert(z(x,y));
Thanks
Can someone explain to me how the attached code works?
I understand the 3 and 4 are passed as the x and y parameters and the function is passed as the z parameter.. But i don understand what parameters are being passed to: function(x,y) { return x * y}??
Also, what is happening in the following line:
alert(z(x,y));
Thanks
function funcObject(x,y,z) {
alert(z(x,y));
}
function testFunction() {
// third parameter is function
funcObject(3,4,function(x,y) { return x * y})
}
testFunction();
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
alert(z(x,y));
So all the above line means is:
The z function i.e function(x,y) { return x * y} is called, and the x,y parameters are passed in to it?? I understand it is called an anonymous function, however i do not understand why such functions are used? What is the advantage over declarative functions?
thanks
So all the above line means is:
The z function i.e function(x,y) { return x * y} is called, and the x,y parameters are passed in to it?? I understand it is called an anonymous function, however i do not understand why such functions are used? What is the advantage over declarative functions?
thanks
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
roma
\\ "alert(z(x,y));" - will call the function passed in parameter z with the two parameters: x and y.
so what you are saying is that above line is equivalent to:
alert(function(x,y) { return x * y}(x,y)); // i.e z = function(x,y) { return x * y}?
it all looks a bit confusing to me, and im not really sure what is the point of this technique?? Perhaps someone can enlighten me / explain in a bit more detail?