I failed to create a mini-library with some useful functions that I have found over the Internet, and I want to use them easily by just including a file to the HTML (like jQuery).
The problem is that some vars and functions share the same name and they are causing problems.
Is there a better solution to this instead of giving crazy names to the vars/funcs like “bbbb123” so the odds that someone is working with a “bbbb123” var is really low?
Yes, you can create an object as a namespace. There are several ways to do this, syntax-wise, but the end result is approximately the same. Your object name should be the thing that no one else will have used.
Just remember, it’s object literal syntax, so you use
label : valueto put things inside it, and notvar label = value;.If you need to declare things first, use a wrapping function to enclose the environment and protect you from the global scope: