I have a javascript file with a lot of global objects. That is, I have a lot of the following sorts of code going on:
var foo = 5;
var bar = "string";
var getStuff = function () {
//...getStuff
}
Question: What is the easiest way for me to place the entirety of this file into an object?
It seems to me my options are as follows:
Wrap the entire file in a
var Object = { ... };
. The problem is that is that I have to change the syntax of how variables and functions are declared.Manually prefix
Object.xxx
before each declaration. This is also a lot of manual work, and makes things slightly verbose.
Is there a better way? Or if not, is there a reason to prefer (1) or (2)?