Looking at your question you must be talking of the case when you run your javascript code on the server, that is node.js or any other fork of it.
In this case the neither the window object or the document object are defined because none of those exist on node so your code will throw a Reference Error. Removing the reference to the document object and testing the this variable
(function(window) {
console.log(window);
console.log(typeof window);
console.log(Object.prototype.toString(window));
}(typeof window !== "undefined" ? window : this));
The output will be
{}
object
[object Object]
That is an empty object wich is a reference to the module.exports object. This is easy to test.
module.exports.test = function () {
console.log('a');
};
(function(window) {
window.test();
}(typeof window !== "undefined" ? window : this));
Will output a in the console. Check this SO question to learn more about the value of the this object in node.js.