Reputation:
I am going to go with this possibly
var my_lib =
{
/*
my_code
*/
}
as a way to not clutter the global name space. Is this OK?
Upvotes: 0
Views: 965
Reputation: 911
There are different ways to accomplish it. I ran into this article by kangax in the past: http://perfectionkills.com/unnecessarily-comprehensive-look-into-a-rather-insignificant-issue-of-global-objects-creation/
which walks you through different approaches. I think this is the best article on the topic.
Upvotes: 0
Reputation: 169391
(function (global) {
/* my code */
global["someName"] = someObject;
})(window);
Upvotes: 1
Reputation: 190945
That's fine, however var
will limit its scope. You might also want to wrap it in a closure as well.
Upvotes: 0