Why does the Closure Compiler generate different code (using advance option) for the following two functions:
var function1 = function() {
return 1 * Math.random();
};
window['function1'] = function1; // export function1
var function2 = function() {
return function1() + 1;
};
window['function2'] = function2; // export function2
This is the code generated:
function a() {
return 1 * Math.random();
}
window.function1 = a;
window.function2 = function() {
return a() + 1; // call to a() fails in a more complex example
};
Notice that function1 has been renamed to a and a is assigned to the global varible function1. With function2 there is no other variable name associated with it. Why?
The reason why I ask is, in the case with my code, the call to function1 from function2 fails because the renamed function1 is not seen as a function call in function2 but rather the Javascript interpreter thinks that a() is a number.
Any insight is appreciated. TIA.