Because variable B stores the reference of the function, when the function changes, B also changes at any time, regardless of the order in which the function appears. Two times of alert (B), although the location is different, but the content is the same.
The Code is as follows:
Function tt ()
{
Alert (11 );
}
Var B = tt;
Var b1 = tt (); // execute the tt () function
For function reference, you can directly assign the function name "tt" to the variable, but it cannot be in the form of function name + brackets "tt ()", because the second method is to directly execute this function.
When a function is called, the variable name and brackets are used, for example, B ().
The Code is as follows:
Function tt ()
{
Alert (11 );
}
Var B = tt;
Alert (B );
Function tt ()
{
Alert (22 );
}
Alert (B );
B ();
Because variable B stores the reference of the function, when the function changes, B also changes at any time, regardless of the order in which the function appears. Two times of alert (B), although the location is different, but the content is the same.
This is just a small experiment. Next we will study the closure problem in js.
Learn how to conquer RIA-JavaScript-based web Client development and the Chinese version of JavaScript authoritative guide.