Preserving and retrieving multiple js instances
<p>i have a 'class' called myClass</p>

<pre><code>myClass= (function(config){
    var _data, _args, _config;
    var pubdata;
    var setData = function(d){_data = d;};
    var getData function(){return _data;};
    var priFun = function(){};
    return {
       setData: setData
       getData: getData
};
})
</code></pre>

<p>in HTML js block, I initiate </p>

<pre><code>var obj1 = myClass(config);
var obj2 = myClass(config);

globalObjList= [];
globalObjList.push({'id': 'obj1', 'obj': obj1});
globalObjList.push({'id': 'obj2', 'obj': obj2});
obj1.setData(data1);
obj2.setData(data2);
</code></pre>

<p>later on, when user perform some action, I want to retrieve obj1 or obj2 based on user's selection, so I can do further operation using the data associated with the object.</p>

<p>for example by clicking button1, retrieving obj1.  I want the something like</p>

<pre><code>var obj = getInstanceById('btn1');
obj.getData(); //this should return me data1
</code></pre>

<p>I'm not sure how getInstanceById function will work.I did something like</p>

<pre><code>getInstanceById = function(id){
    //match the id with the id in globalObjList array, and return the obj
}
</code></pre>

<p>however, this way, when get the obj this way, and do getData() it 's not the right obj that i want....</p>

<p>How can I do this other than declare obj1 and obj2 as global var?</p>
