1. Original function
Output results: 1
2, plus window parameters
Output Result: Window object
Note: Window at this time is not a global variable, but a local variable
3, about the formal parameter must pass window? Of course it's not necessary.
Output Result: Window object
A parameter can pass any character, as long as the argument passes through the window. Function
4, the function of a code will be compressed, save space
5, function two improve performance
function in the execution process, can find the window in the parameters, do not go to the global scope to find, that is, high efficiency, improve performance.
6. Is it possible to pass the argument or not?
Yes, argument parameters are not passed, internal or accessible to window, this is because window is a global variable, where it can be accessed, at this time in the global scope of the Search window, low efficiency, and the line will not be compressed.
7, why to pass in undefined?
Within the scope of the self-invocation anonymous function, ensure that undefined is truly undefined, because undefined can be overridden and assigned.
Conclusion: window is intended as an argument: improves performance and facilitates code compression.
Undefined is intended as a formal parameter: Prevents the value of undefined from being modified.
The role of JavaScript window and undefined as parameters