JavaScript Window object always accessible?

Viewed 1995

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:

  1. The developer can not with 100% certainty know that window is accessible from within the local function scope?
  2. Is is good practice because you make your intentions clear to other developers that read your code.
  3. You've seen John Resig do it so it must be finger lickin' good!

What do you think?

3 Answers
Related