We see this approach used all the time:
(function (window) {
var document = window.document,
location = window.location,
navigator = window.navigator;
})(window)
When studying above snippet I wonder why a globally accessible object like window
is passed as an argument to a function. Could it be that:
- The developer can not with 100% certainty know that window is accessible from within the local function scope?
- Is is good practice because you make your intentions clear to other developers that read your code.
- You've seen John Resig do it so it must be finger lickin' good!
What do you think?