I would say that you really do not want to make many global variables. Most likely, you can simply create one global object or array and attach all other variables to it. In this case, you probably need an object:
var myIds = {}; function makeSomething(id) {
Then, to get this information after a while, you can get it with this:
var something = myIds[id];
The reason for this proposal is multiple. First of all, you want to minimize the number of global variables, since each global is the probability of a name clash with some other script that you could use. Secondly, when tracking a collection of related data, it is best programming practice to keep it in one specific data structure, and not just throw it in a giant global box with all the other data.
You can even create an object that manages all this for you:
function idFactory() { this.ids = {}; } idFactory.prototype = { makeSomething: function(id) {
source share