What makes you think the result of a function is being assigned? Take a look at this example:
function calc(x, y)
{
return x+y;
}
var result = calc(1,2);
alert(result);
result = function(x,y) { return x+y; };
alert(result);
In order to get the result of a function, you have to execute the function. How do you execute a function? Like this:
calc(1,2);
Or like this:
var result = function calc(x, y)
{
return x+y;
}(1,2);
In both cases, the part that executes the function is: (1,2). The parentheses are the function execution operator—except when the parentheses appear in the middle of a function definition, like here:
function calc(x, y)
{
return x+y;
}
The parentheses there do not execute the function.
So what does your code example do? Look at this example:
function calc(x, y)
{
alert(x+y);
}
do_stuff = calc;
do_stuff(1, 2);
Your example actually assigns the function itself to a special variable. Then when a specific event takes place (i.e. the ready state changes), js executes whatever function is assigned to that variable. In js, you can assign numbers or strings to variables–and you can assign functions to variables too. In fact, the function name in the function definition is just a variable that stores the function itself:
function do_stuff(x, y)
{
return x() + y()
}
function func1()
{
return 2;
}
function func2()
{
return 3;
}
alert( do_stuff(func1, func2) );