Passing document As An Argument

Quite often, I define variables like so:


var something = (function () {
    if (x) {
        ...
    } else {
        ...
    }
}());

A good deal of the time, I’ll use document inside that closure. Like, document.getElementById for example. Then, when I run it through JSLint, I get a bunch of errors that “document” hasn’t been defined. So then I do this:


var something = (function (document) {
    if (x) {
        ...
    } else {
        ...
    }
}(document));

That makes it so that the error only shows up one time in JSLint, which makes me feel good. This is solely to satisfy my own personal tics. I know I shouldn’t code exactly according to what JSLint says, I know that it’s only a guide, blah blah blah.

My question is, are there any performance issues with doing this? With passing the document object to an anonymous function that’s only being executed once, immediately?

You don’t need to make use of that work-around.

When your code is intended to run in a web browser, the document object will always be available to you.

JSLint allows you to specify that assumption too, by providing a checkbox on the JSLint page called “Assume a browser”