prank points to the original function, not to scareMe .
Take a look at this example:
var scareMe = 1; var prank = scareMe; scareMe = 2;
You do not expect a change to scareMe change prank , right? It exactly matches the functions.
var scareMe = function() { alert( 'Boo' ); }; var prank = scareMe; scareMe = function() { alert( 'Double boo!' ); };
There is no difference between integers and functions in this regard. prank remains unchanged even when scareMe changes. The fact that scareMe changes from within another function does not change this fact.
Confusion can arise from the way objects are commonly used. This does not replace the original function as often as you can change the properties of the object.
var scareMe = { message: 'Boo' }; var prank = scareMe; scareMe.message = 'Double boo!'; alert( prank.message );
This is not what you do with the functions in the original example. Changing a variable pointing to a completely different function does not change the reference to the function in another variable.
source share